Overriding mod_mainmenu output structure
- jazbek
- Joomla! Apprentice
- Posts: 39
- Joined: Thu Nov 16, 2006 7:47 pm
Re: Overriding mod_mainmenu output structure
I definitely will, if I have time to go back and review the code once I am done pounding out this site!
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
Probably you're right, but I've never tried, yet.doonee wrote: I guess it'd be well within the ballpark to use these override approaches to have mainmenu ouput the 'Alias' field [...] as the title attribute of a menu item link, correct ?
Have you did some experiment in this case?
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
Perfect...we're waiting the code!jazbek wrote:I definitely will, if I have time to go back and review the code once I am done pounding out this site!

--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
-
- Joomla! Fledgling
- Posts: 4
- Joined: Sun Mar 09, 2008 8:33 pm
Re: Overriding mod_mainmenu output structure
Hi all, I read with interest since it looks like it will be necessary to override the mod_mainmenu code to solve my problem.
Problem: The menus are created in unordered lists as list items (this part is not the problem
. All menu items that are links are created with <a> </a>. Menu separators (since they are not links) are simply li. So, I happily add CSS padding to my li a items, and all my linked menu items look great, but that isn't possible for my menu separator since it is just an li (with class=separator). Is there any way to style my menu separator to have the same padding as the other menu items (or any padding at all would be fantastic!) without modifying the code the menu outputs?
Thanks for your kind attention.
-Wumbriac
Problem: The menus are created in unordered lists as list items (this part is not the problem

Thanks for your kind attention.
-Wumbriac
- jazbek
- Joomla! Apprentice
- Posts: 39
- Joined: Thu Nov 16, 2006 7:47 pm
Re: Overriding mod_mainmenu output structure
is there any reason you can't just apply the padding to all the li elements in your menu, instead of li a?wumbriac wrote: Problem: The menus are created in unordered lists as list items (this part is not the problem. All menu items that are links are created with <a> </a>. Menu separators (since they are not links) are simply li. So, I happily add CSS padding to my li a items, and all my linked menu items look great, but that isn't possible for my menu separator since it is just an li (with class=separator). Is there any way to style my menu separator to have the same padding as the other menu items (or any padding at all would be fantastic!) without modifying the code the menu outputs?
-
- Joomla! Apprentice
- Posts: 12
- Joined: Fri May 25, 2007 3:36 pm
Re: Overriding mod_mainmenu output structure
There's too much data in the objects at the top of the callback... can anyone point to the property/method I would need to access to know which module position the menu is drawing in?
I want to change the structure for one specific module location on my template. With other overrides it's easy because you just name your function what you put in the jdoc:include style attribute, but overriding default.php's xml callback appears to affect all menus equally.
I want to change the structure for one specific module location on my template. With other overrides it's easy because you just name your function what you put in the jdoc:include style attribute, but overriding default.php's xml callback appears to affect all menus equally.
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
You're right, since I rewrite whole menu function, all menus are modified. But you can just use CSS to customized every menu module you want, adding a custom css class to advanced module parameters.samthurston wrote: I want to change the structure for one specific module location on my template.
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
-
- Joomla! Apprentice
- Posts: 12
- Joined: Fri May 25, 2007 3:36 pm
Re: Overriding mod_mainmenu output structure
Ordinarily that would be fine, but the customization I am doing is more involved than CSS can handle. is there a way to do a special case for one position without hacking the core files? Because at this point I'm looking at the inclusion of legacy.php and seriously considering hacking it... unfortunately it would make my final product not "simply" distributable, and that is an eventual goal.midimarcus wrote:But you can just use CSS to customized every menu module you want
I suppose I could distribute a complete re-packaging of mod_mainmenu along with my template, it just seems like the overrides were built in to avoid this situation.
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
I'm sorry but without more info about the goal you have to reach I can't be more helpful on giving you more suggestions.samthurston wrote: Ordinarily that would be fine, but the customization I am doing is more involved than CSS can handle. is there a way to do a special case for one position without hacking the core files?
Yes you can.samthurston wrote: I suppose I could distribute a complete re-packaging of mod_mainmenu along with my template, it just seems like the overrides were built in to avoid this situation.
My override solution can be easily distributed inside template package without having to hack anything in core mod_mainmenu!
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
-
- Joomla! Apprentice
- Posts: 12
- Joined: Fri May 25, 2007 3:36 pm
Re: Overriding mod_mainmenu output structure
Quite alright. Since you asked...midimarcus wrote: I'm sorry but without more info about the goal you have to reach I can't be more helpful on giving you more suggestions.
For semantic reasons, in one of my module positions in particular I need the menus formatted as definition lists rather than unordered lists. The rest of the menus should be standard. So for these menus I need to swap out the ul's for dl's and the li's for dt's doing something like this within the callback:
Code: Select all
/* definition lists */
if ($node->name() == 'li'){
$node->_name = 'dt';
}
if ($node->name() == 'ul'){
if ($node->attributes('class')){
$node->addAttribute('class', $node->attributes('class').' nav3-grid');
}else{
$node->addAttribute('class', 'nav3-grid');
}
$node->_name = 'dl';
}
edit:
I'm starting to pull out my hair because for some strange reason (possibly a php scope issue?) I cannot access the $params object that would at least contain the menu name ($params->get('menutype')) by doing
global $params;
from inside the callback.
edit2:
I finally got it working, by making alternate callback functions, then assigning the callback passed to ::render() based on stuff in $params. It still would be handy for that entire params structure to get passed to the callback instead of the pared-down one that does. In the helper class, it gets passed down the chain just one step shy of where I needed it

- ripplegraphics
- Joomla! Intern
- Posts: 74
- Joined: Sun Jan 13, 2008 1:33 am
Re: Overriding mod_mainmenu output structure
Thanks for that...it's helped me too...
...worked like a charm!
...worked like a charm!

-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
Really good!samthurston wrote: I finally got it working, by making alternate callback functions, then assigning the callback passed to ::render() based on stuff in $params. It still would be handy for that entire params structure to get passed to the callback instead of the pared-down one that does. In the helper class, it gets passed down the chain just one step shy of where I needed it
Please, could you post your code for us?
Thanks.
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
-
- Joomla! Apprentice
- Posts: 12
- Joined: Fri May 25, 2007 3:36 pm
Re: Overriding mod_mainmenu output structure
yeah, no idea why i didn't already do that.
up to about line 82 it's just like the normal default.php, right below that i have my slightly modified callback (changed at line 168), and down at 186 is where the $params come into play for callback selection.
Because I'm kinda neurotic I also re-implemented the helper class so that it passes that the params object to the callback so that you can do other cool stuff within that callback, since it's the only way to achieve some derivative menu effects: I'm thinking about submitting this to the joomla 1.5 codebase, if they'll have it, but as it stands, you can include the alternate helper class in your default.php and then just calling the custom render method allows your callback loop to operate on that structure. would anyone else find this useful? I'll post it if requested.
Offhand, does anyone know enough about how php works to explain why global $params doesn't work in the callback? it's been bugging me, and looking at the code it really doesn't make sense.
up to about line 82 it's just like the normal default.php, right below that i have my slightly modified callback (changed at line 168), and down at 186 is where the $params come into play for callback selection.
Because I'm kinda neurotic I also re-implemented the helper class so that it passes that the params object to the callback so that you can do other cool stuff within that callback, since it's the only way to achieve some derivative menu effects: I'm thinking about submitting this to the joomla 1.5 codebase, if they'll have it, but as it stands, you can include the alternate helper class in your default.php and then just calling the custom render method allows your callback loop to operate on that structure. would anyone else find this useful? I'll post it if requested.
Offhand, does anyone know enough about how php works to explain why global $params doesn't work in the callback? it's been bugging me, and looking at the code it really doesn't make sense.
You do not have the required permissions to view the files attached to this post.
- kavaXtreme
- Joomla! Intern
- Posts: 74
- Joined: Tue Dec 13, 2005 9:56 pm
- Location: Oregon
- Contact:
Re: Overriding mod_mainmenu output structure
@midimarcus
Your override was exactly what I was looking for. Thanks!
I'm having one problem with it though that I'm hoping you might have some ideas about. I'm getting a "Call to a member function on a non-object" error on line 91, which is where the lastItem class is added. When I comment out that section, the rest works fine. I have no idea why I seem to be the only one getting that error since I'm using your file unmodified.
Your override was exactly what I was looking for. Thanks!
I'm having one problem with it though that I'm hoping you might have some ideas about. I'm getting a "Call to a member function on a non-object" error on line 91, which is where the lastItem class is added. When I comment out that section, the rest works fine. I have no idea why I seem to be the only one getting that error since I'm using your file unmodified.
- Bible Yellow Pages: http://www.bibleyp.com
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
It's quite strange, could you post more details about this error?kavaXtreme wrote:I'm getting a "Call to a member function on a non-object" error on line 91, which is where the lastItem class is added.
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
- kavaXtreme
- Joomla! Intern
- Posts: 74
- Joined: Tue Dec 13, 2005 9:56 pm
- Location: Oregon
- Contact:
Re: Overriding mod_mainmenu output structure
Sure, though if I don't mention something you have a question about, feel free to ask. I'm a PHP ubernovice.
I'm using Joomla 1.5.1, PHP 4.4.2. When I tried to run the template with your override, all I got was a white screen with the error mesage about line 91. Armed with that info, I commented out the whole "if" statement, and everything worked except of course the "lastItem" class. After a little playing around, it seems the system doesn't agree that my_parent has a children object. And that was all the further I got.

I'm using Joomla 1.5.1, PHP 4.4.2. When I tried to run the template with your override, all I got was a white screen with the error mesage about line 91. Armed with that info, I commented out the whole "if" statement, and everything worked except of course the "lastItem" class. After a little playing around, it seems the system doesn't agree that my_parent has a children object. And that was all the further I got.
- Bible Yellow Pages: http://www.bibleyp.com
-
- Joomla! Enthusiast
- Posts: 139
- Joined: Wed Jan 23, 2008 5:35 pm
Re: Overriding mod_mainmenu output structure
Whilst I am able to override the file, I actually wish to make amends to the helper.php function associated with the mod_mainmenu file. I want to create an empty span tag in my menu to allow some accessible hiding of my menu items when Images are offand CSS is on. How do I go about overriding helper.php?
- M4rc0
- Joomla! Explorer
- Posts: 311
- Joined: Wed Sep 27, 2006 1:47 pm
- Contact:
Re: Overriding mod_mainmenu output structure
midmarcus, I was looking exactly for this, got your file, created an template/mod_mainmenu/default.php
But it's not working yet.
I have a mainmenu that should have a "|" separator, since i'm using this as a footer menu.
The menu is a list, it's there working well with my CSS but no separator between them D:
Any ideas ?
But it's not working yet.
I have a mainmenu that should have a "|" separator, since i'm using this as a footer menu.
The menu is a list, it's there working well with my CSS but no separator between them D:
Any ideas ?
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
The right path is template/html/mod_mainmenu/default.php.M4rc0 wrote:midmarcus, I was looking exactly for this, got your file, created an template/mod_mainmenu/default.php
Please check it out.
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
- M4rc0
- Joomla! Explorer
- Posts: 311
- Joined: Wed Sep 27, 2006 1:47 pm
- Contact:
Re: Overriding mod_mainmenu output structure
Yes yes that was a typo, soorrymidimarcus wrote:The right path is template/html/mod_mainmenu/default.php.M4rc0 wrote:midmarcus, I was looking exactly for this, got your file, created an template/mod_mainmenu/default.php
Please check it out.

So yea, it's there in template/html/mod_mainmenu but no pretty separator yet.
(Thanks for the quick reply!)
- spike00
- Joomla! Intern
- Posts: 55
- Joined: Wed Jan 25, 2006 10:56 pm
- Location: Busto Arsizio (VA) - Italy
- Contact:
Re: Overriding mod_mainmenu output structure
Hello, I'd need just to remove the span tag surrounding the name of each menu item:
to become
From what I read, I suppose the override of default.php is not the way to achieve this, right?
But I haven't understood where (and why???) these span are inserted.
I also tried (since I'm using jquery) to traverse the dom to get rid of the span (writing a kind of unwrap function in jquery) but without success till now.
Why do I need that? because I wrote a jquery script that works on span tags (dinamycally added inside the a tag, without content) and having the span surrounding the text (item name) mess up everything...
Any hint will be appreciated, thanks
Code: Select all
<li><a><span>Item name</span></a></li>
Code: Select all
<li><a>Item name</a></li>
But I haven't understood where (and why???) these span are inserted.
I also tried (since I'm using jquery) to traverse the dom to get rid of the span (writing a kind of unwrap function in jquery) but without success till now.
Why do I need that? because I wrote a jquery script that works on span tags (dinamycally added inside the a tag, without content) and having the span surrounding the text (item name) mess up everything...
Any hint will be appreciated, thanks
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
I intend my solution as a temporary workaround.
Personally I prefer working more with CSS than with PHP, above all because I've have many site to manage and the more joomla core is keep to default the more joomla updates management is easier.
In the case of span tag i just add a few lines to CSS to declare explicitly every single class.
I've attached an example of what I did with my mod_mainmenu.php and a CSS, the zip archive contains both css and explained result image.
Css is not consistent in some comments, and, obviously, some classes not mentioned in the example are inherited by other css!
But I hope it's understandable!
Personally I prefer working more with CSS than with PHP, above all because I've have many site to manage and the more joomla core is keep to default the more joomla updates management is easier.
In the case of span tag i just add a few lines to CSS to declare explicitly every single class.
I've attached an example of what I did with my mod_mainmenu.php and a CSS, the zip archive contains both css and explained result image.
Css is not consistent in some comments, and, obviously, some classes not mentioned in the example are inherited by other css!
But I hope it's understandable!

You do not have the required permissions to view the files attached to this post.
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
- spike00
- Joomla! Intern
- Posts: 55
- Joined: Wed Jan 25, 2006 10:56 pm
- Location: Busto Arsizio (VA) - Italy
- Contact:
Re: Overriding mod_mainmenu output structure
I solved my problem simply adding a class to the span that I add dinamically via jquery and then in the js and in the css referring to this class instead of the simple span.
I think of this as a workaround and believe that a more simple way to customize the output (all the output) structure of this module would be better
I think of this as a workaround and believe that a more simple way to customize the output (all the output) structure of this module would be better

- M4rc0
- Joomla! Explorer
- Posts: 311
- Joined: Wed Sep 27, 2006 1:47 pm
- Contact:
Re: Overriding mod_mainmenu output structure
midimarcus,
I told you it wasn't working for me, but now with display errors on it shows the following fatal error:
Can you look into your patch?
I really want that separator
I told you it wasn't working for me, but now with display errors on it shows the following fatal error:
Code: Select all
Call to a member function on a non-object in /mod_mainmenu/default.php on line 91
I really want that separator

-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
What changes have you done to that file?
--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
- M4rc0
- Joomla! Explorer
- Posts: 311
- Joined: Wed Sep 27, 2006 1:47 pm
- Contact:
Re: Overriding mod_mainmenu output structure
none?
Can you try running your file with show errors enabled ?
Can you try running your file with show errors enabled ?
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
Yes, but not in short time. I've a lot of work to finish within september!M4rc0 wrote:none?
Can you try running your file with show errors enabled ?

--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
- M4rc0
- Joomla! Explorer
- Posts: 311
- Joined: Wed Sep 27, 2006 1:47 pm
- Contact:
Re: Overriding mod_mainmenu output structure
It's okay, i can waitmidimarcus wrote:Yes, but not in short time. I've a lot of work to finish within september!M4rc0 wrote:none?
Can you try running your file with show errors enabled ?

Meanwhile maybe i'll take a peek, if i find anything i'll post here.
Good luck with your work!
-
- Joomla! Apprentice
- Posts: 20
- Joined: Thu Feb 02, 2006 1:01 pm
Re: Overriding mod_mainmenu output structure
Thank you!
Oh...fell free to send some reminder post to me!
Oh...fell free to send some reminder post to me!

--
Marco Giorgetti :: http://www.marcogiorgetti.com
Marco Giorgetti :: http://www.marcogiorgetti.com
- hotnuts21
- Joomla! Explorer
- Posts: 315
- Joined: Wed Aug 17, 2005 11:11 pm
Re: Overriding mod_mainmenu output structure
There are some great tips in this article and I have finally worked out how to add class, id etc to the mod mainmenu using the default replace methods ($addattribute etc). But one thing I am really struggling with is how to add in a whole new item to the string?
For instance I want to add in <em> </em> after the closing span so it would look like this
The site is using css to replace the text with image tabs, and this is the only way to get it working in ie5.5 and 6 properly.
In the helper class this is actually fairly straightforward to achieve by just changing lines 283 and 291 to the following
But I dont want to hack the core helper file!! So what do I need to use to write the span in?
For instance I want to add in <em> </em> after the closing span so it would look like this
Code: Select all
<a href="l"><span>Tour</span><em></em></a>
In the helper class this is actually fairly straightforward to achieve by just changing lines 283 and 291 to the following
Code: Select all
$tmp->name = '<span><![CDATA['.$item->name.']]></span><em><![CDATA[ ]]>