Overriding mod_mainmenu output structure

Everything to do with Joomla! 1.5 templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
User avatar
jazbek
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Thu Nov 16, 2006 7:47 pm

Re: Overriding mod_mainmenu output structure

Post by jazbek » Sat Mar 29, 2008 2:02 am

I definitely will, if I have time to go back and review the code once I am done pounding out this site!

 
midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Sat Mar 29, 2008 2:09 am

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 ?
Probably you're right, but I've never tried, yet.
Have you did some experiment in this case?
--
Marco Giorgetti :: http://www.marcogiorgetti.com

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Sat Mar 29, 2008 2:12 am

jazbek wrote:I definitely will, if I have time to go back and review the code once I am done pounding out this site!
Perfect...we're waiting the code! :geek:
--
Marco Giorgetti :: http://www.marcogiorgetti.com

wumbriac
Joomla! Fledgling
Joomla! Fledgling
Posts: 4
Joined: Sun Mar 09, 2008 8:33 pm

Re: Overriding mod_mainmenu output structure

Post by wumbriac » Sun Mar 30, 2008 8:45 pm

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

User avatar
jazbek
Joomla! Apprentice
Joomla! Apprentice
Posts: 39
Joined: Thu Nov 16, 2006 7:47 pm

Re: Overriding mod_mainmenu output structure

Post by jazbek » Mon Mar 31, 2008 9:01 pm

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?
is there any reason you can't just apply the padding to all the li elements in your menu, instead of li a?

samthurston
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri May 25, 2007 3:36 pm

Re: Overriding mod_mainmenu output structure

Post by samthurston » Sun Apr 27, 2008 1:14 am

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.

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Sun Apr 27, 2008 8:41 am

samthurston wrote: I want to change the structure for one specific module location on my template.
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.
--
Marco Giorgetti :: http://www.marcogiorgetti.com

samthurston
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri May 25, 2007 3:36 pm

Re: Overriding mod_mainmenu output structure

Post by samthurston » Sun Apr 27, 2008 4:13 pm

midimarcus wrote:But you can just use CSS to customized every menu module you want
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.

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.

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Sun Apr 27, 2008 5:30 pm

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?
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: 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.
Yes you can.
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

samthurston
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri May 25, 2007 3:36 pm

Re: Overriding mod_mainmenu output structure

Post by samthurston » Sun Apr 27, 2008 11:23 pm

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.
Quite alright. Since you asked...

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';
	}
I'm just not sure what sort of conditional I would have to wrap that in so that it only occurs in one position. personally I don't care how this is specified, if it's through appending a special class attribute to that menu, or going by name... that doesn't matter as much as just being able to do it selectively. I will be using a custom style attribute in the jdoc:include for the purposes of another module that appears in the same position as the menu, so if that's something we can use, then that would be great too.

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 :)

User avatar
ripplegraphics
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Sun Jan 13, 2008 1:33 am

Re: Overriding mod_mainmenu output structure

Post by ripplegraphics » Sat May 03, 2008 12:10 pm

Thanks for that...it's helped me too...
...worked like a charm! ;D

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Sun May 04, 2008 9:59 am

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 :)
Really good!
Please, could you post your code for us?
Thanks.
--
Marco Giorgetti :: http://www.marcogiorgetti.com

samthurston
Joomla! Apprentice
Joomla! Apprentice
Posts: 12
Joined: Fri May 25, 2007 3:36 pm

Re: Overriding mod_mainmenu output structure

Post by samthurston » Sun May 04, 2008 8:34 pm

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.
You do not have the required permissions to view the files attached to this post.

User avatar
kavaXtreme
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Tue Dec 13, 2005 9:56 pm
Location: Oregon
Contact:

Re: Overriding mod_mainmenu output structure

Post by kavaXtreme » Wed May 07, 2008 5:54 pm

@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.
- Bible Yellow Pages: http://www.bibleyp.com

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Thu May 08, 2008 6:43 am

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.
It's quite strange, could you post more details about this error?
--
Marco Giorgetti :: http://www.marcogiorgetti.com

User avatar
kavaXtreme
Joomla! Intern
Joomla! Intern
Posts: 74
Joined: Tue Dec 13, 2005 9:56 pm
Location: Oregon
Contact:

Re: Overriding mod_mainmenu output structure

Post by kavaXtreme » Thu May 08, 2008 4:25 pm

Sure, though if I don't mention something you have a question about, feel free to ask. I'm a PHP ubernovice. :D

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

babberoo
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 139
Joined: Wed Jan 23, 2008 5:35 pm

Re: Overriding mod_mainmenu output structure

Post by babberoo » Wed May 14, 2008 1:14 pm

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?

User avatar
M4rc0
Joomla! Explorer
Joomla! Explorer
Posts: 311
Joined: Wed Sep 27, 2006 1:47 pm
Contact:

Re: Overriding mod_mainmenu output structure

Post by M4rc0 » Mon Aug 25, 2008 3:23 pm

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 ?

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Mon Aug 25, 2008 3:42 pm

M4rc0 wrote:midmarcus, I was looking exactly for this, got your file, created an template/mod_mainmenu/default.php
The right path is template/html/mod_mainmenu/default.php.
Please check it out.
--
Marco Giorgetti :: http://www.marcogiorgetti.com

User avatar
M4rc0
Joomla! Explorer
Joomla! Explorer
Posts: 311
Joined: Wed Sep 27, 2006 1:47 pm
Contact:

Re: Overriding mod_mainmenu output structure

Post by M4rc0 » Mon Aug 25, 2008 4:02 pm

midimarcus wrote:
M4rc0 wrote:midmarcus, I was looking exactly for this, got your file, created an template/mod_mainmenu/default.php
The right path is template/html/mod_mainmenu/default.php.
Please check it out.
Yes yes that was a typo, soorry :D

So yea, it's there in template/html/mod_mainmenu but no pretty separator yet.

(Thanks for the quick reply!)

User avatar
spike00
Joomla! Intern
Joomla! Intern
Posts: 55
Joined: Wed Jan 25, 2006 10:56 pm
Location: Busto Arsizio (VA) - Italy
Contact:

Re: Overriding mod_mainmenu output structure

Post by spike00 » Mon Aug 25, 2008 5:40 pm

Hello, I'd need just to remove the span tag surrounding the name of each menu item:

Code: Select all

<li><a><span>Item name</span></a></li>
to become

Code: Select all

<li><a>Item name</a></li>
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
Paolo De Dionigi
Moderator of Zen Cart Italy

http://www.atfriends.net

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Tue Aug 26, 2008 7:05 am

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! ;)
You do not have the required permissions to view the files attached to this post.
--
Marco Giorgetti :: http://www.marcogiorgetti.com

User avatar
spike00
Joomla! Intern
Joomla! Intern
Posts: 55
Joined: Wed Jan 25, 2006 10:56 pm
Location: Busto Arsizio (VA) - Italy
Contact:

Re: Overriding mod_mainmenu output structure

Post by spike00 » Tue Aug 26, 2008 8:02 am

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 ;)
Paolo De Dionigi
Moderator of Zen Cart Italy

http://www.atfriends.net

User avatar
M4rc0
Joomla! Explorer
Joomla! Explorer
Posts: 311
Joined: Wed Sep 27, 2006 1:47 pm
Contact:

Re: Overriding mod_mainmenu output structure

Post by M4rc0 » Tue Sep 09, 2008 10:06 am

midimarcus,

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
Can you look into your patch?
I really want that separator :)

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Tue Sep 09, 2008 5:01 pm

What changes have you done to that file?
--
Marco Giorgetti :: http://www.marcogiorgetti.com

User avatar
M4rc0
Joomla! Explorer
Joomla! Explorer
Posts: 311
Joined: Wed Sep 27, 2006 1:47 pm
Contact:

Re: Overriding mod_mainmenu output structure

Post by M4rc0 » Tue Sep 09, 2008 6:00 pm

none?

Can you try running your file with show errors enabled ?

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Wed Sep 10, 2008 6:22 am

M4rc0 wrote:none?

Can you try running your file with show errors enabled ?
Yes, but not in short time. I've a lot of work to finish within september! :(
--
Marco Giorgetti :: http://www.marcogiorgetti.com

User avatar
M4rc0
Joomla! Explorer
Joomla! Explorer
Posts: 311
Joined: Wed Sep 27, 2006 1:47 pm
Contact:

Re: Overriding mod_mainmenu output structure

Post by M4rc0 » Wed Sep 10, 2008 7:46 am

midimarcus wrote:
M4rc0 wrote:none?

Can you try running your file with show errors enabled ?
Yes, but not in short time. I've a lot of work to finish within september! :(
It's okay, i can wait :)

Meanwhile maybe i'll take a peek, if i find anything i'll post here.

Good luck with your work!

midimarcus
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Feb 02, 2006 1:01 pm

Re: Overriding mod_mainmenu output structure

Post by midimarcus » Wed Sep 10, 2008 11:35 am

Thank you!
Oh...fell free to send some reminder post to me! ;)
--
Marco Giorgetti :: http://www.marcogiorgetti.com

User avatar
hotnuts21
Joomla! Explorer
Joomla! Explorer
Posts: 315
Joined: Wed Aug 17, 2005 11:11 pm

Re: Overriding mod_mainmenu output structure

Post by hotnuts21 » Tue Oct 14, 2008 6:49 pm

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

Code: Select all

<a href="l"><span>Tour</span><em></em></a>
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

Code: Select all

$tmp->name	 = '<span><![CDATA['.$item->name.']]></span><em><![CDATA[&nbsp;]]>
But I dont want to hack the core helper file!! So what do I need to use to write the span in?

 

Locked

Return to “Templates for Joomla! 1.5”