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.
dynedain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Wed Aug 24, 2005 7:20 pm
Location: Los Angeles
Contact:

Overriding mod_mainmenu output structure

Post by dynedain » Mon Dec 03, 2007 8:30 pm

Has anyone had any success overriding the mainmenu module?

I know the recommended method is to pull the files from /modules/mod_module/tmpl and copy them to your template's html folder, but mod_mainmenu doesn't use standard templating files. Instead it does a bunch of XML parsing.

What I'd like to do is take the main menu ouput:

Code: Select all

<ul>
    <li><a href="url"><span>Item Name</span></a></li>
    <li><a href="url"><span>Item Name</span></a></li>
</ul>
and restructure it so that the span encloses the instead of the other way around:

Code: Select all

<ul>
    <li><span><a href="url">Item Name</a></span></li>
    <li><span><a href="url">Item Name</a></span></li>
</ul>
But I'm getting completely thrown off since mod_mainmenu does a bunch of XML parsing.

Anyone have an idea how to handle this?

User avatar
samtherobot
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Dec 05, 2005 11:57 pm
Location: London, Ontario
Contact:

Re: Overriding mod_mainmenu output structure

Post by samtherobot » Tue Jan 08, 2008 3:19 pm

I was considering this also until I figured out how it was building the menu.

If you look in /modules/mod_mainmenu/helper.php find the method "render".  Basically it is taking an XML object and running a method that converts it to an html unordered list.

Code: Select all

echo JFilterOutput::ampReplace($xml->toString((bool)$params->get('show_whitespace')));
Its the $xml->toString command that is doing the conversion. 

I'm not sure if it's possible to override or extend this method but you could just not use it and parse the XML object yourself.  That was not something I was prepared to do so I've abandoned that idea for now.  I'm sure there will be more menu modules out in the near future that will help with this.

User avatar
ivanicus
Joomla! Intern
Joomla! Intern
Posts: 72
Joined: Fri Jul 06, 2007 6:15 am
Location: Havana City, Cuba
Contact:

Re: Overriding mod_mainmenu output structure

Post by ivanicus » Tue Jan 08, 2008 3:25 pm

I ALSO wanted to override that output... but actually you can do with just CSS whatever layout you'd like.. so I abbandoned my quest...

Is REALLY necesary to override it? at least for the time being???? :-|
Free speech for the dumb!

dynedain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Wed Aug 24, 2005 7:20 pm
Location: Los Angeles
Contact:

Re: Overriding mod_mainmenu output structure

Post by dynedain » Tue Jan 08, 2008 5:10 pm

ivanicus wrote: I ALSO wanted to override that output... but actually you can do with just CSS whatever layout you'd like.. so I abbandoned my quest...

Is REALLY necesary to override it? at least for the time being???? :-|
Well, yes.

This default structure does not work for me in certain circumstances:

Code: Select all

<ul>
   <li>
      <a><span></span></a>
   </li>
   <li>
      <a><span></span></a>
      <ul>
          <li>
            <a><span></span></a>
         </li>
      </ul>
    <li>
</ul>
There are quite a few times when I need this structure instead:

Code: Select all

<ul>
   <li>
      <span><a></a></span>
   </li>
   <li>
      <span><a></a></span>
      <ul>
          <li>
            <span><a></a></span>
         </li>
      </ul>
    </li>
</ul>
Or even this:

Code: Select all

<ul>
   <li>
      <span><a></a></span>
   </li>
   <li>
      <span><a></a></span>
   </li>
</ul>
<ul>
   <li>
      <span><a></a></span>
   </li>
   <li>
      <span><a></a></span>
   </li>
</ul>


It's subtlety different, but I frequently have situations (using sIFR) where I need to address an element within the list item, and it can't be the anchor, it has to be a container enclosing the anchor. Addressing the list item doesn't work because of the nested submenus. The only work around I've been able to come up with in these situations is to make additional menu modules for the submenus and adjust a lot of options in the modules. Not a very elegant solution, and it requires the site administrator (not me) to have a thorough understanding of how those options work. I would much rather have a single menu module and have the template control the nesting properly.

User avatar
ivanicus
Joomla! Intern
Joomla! Intern
Posts: 72
Joined: Fri Jul 06, 2007 6:15 am
Location: Havana City, Cuba
Contact:

Re: Overriding mod_mainmenu output structure

Post by ivanicus » Tue Jan 08, 2008 6:53 pm

Well... in THAT particular case... then its really needed ;-)

Another (CRUDE) workaround, would be to take the output of the menu module (the list and such) and restructure it as needed using DOM manipulation in Javascript (think prototype, jQuery, etc.),

OR before the page is sent to the browser using PHP (I think I found some kind of PHP implementation of JQuery or other javascript library that lets you work with html in PHP the same way you do it in the original JS library... sorry, dont remember which one...)

Haven't tried it myself... just guessing ;-)  hard work though!!! :-O
Free speech for the dumb!

dynedain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Wed Aug 24, 2005 7:20 pm
Location: Los Angeles
Contact:

Re: Overriding mod_mainmenu output structure

Post by dynedain » Tue Jan 08, 2008 7:02 pm

Yeah, I've thought about those options as well and they're all pretty crude. I guess overriding the XML generator is the best, but that seems really overkill for something that should be simple. I wish the menu module had followed the template approach that has been recommended for 1.5. It would have made it a lot easier to override and work with.

User avatar
ivanicus
Joomla! Intern
Joomla! Intern
Posts: 72
Joined: Fri Jul 06, 2007 6:15 am
Location: Havana City, Cuba
Contact:

Re: Overriding mod_mainmenu output structure

Post by ivanicus » Tue Jan 08, 2008 7:26 pm

I drifted WAY TOO FAR in my previous post!!!

Yes, the mod_mainmenu CAN be overriden, but the approach is different than with the rest of the modules... (just as you stated)

either way... though understanding of PHP & XML is needed :-(
Free speech for the dumb!

User avatar
samtherobot
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Dec 05, 2005 11:57 pm
Location: London, Ontario
Contact:

Re: Overriding mod_mainmenu output structure

Post by samtherobot » Tue Jan 08, 2008 7:58 pm

It might help you if you do a print_r right after the menu XML object is created.

Goto line 150 in /modules/mod_mainmenu/helper.php

Code: Select all

$xml = modMainMenuHelper::getXML($params->get('menutype'), $params, $callback);
print_r ( $xml );
When you do that you'll see that $xml is a JSimpleXMLElement Object.  If you look up info on this class you'll find it has all the methods you need to manipulate the XML.  What I was saying is you can manipulate that object with those SimpleXML methods and then loop over it and output it however you want.

madamep
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Mon Nov 19, 2007 11:27 pm

Re: Overriding mod_mainmenu output structure

Post by madamep » Thu Jan 10, 2008 9:58 pm

Hi there,

I actually have a related Q about manipulating mod_mainmenu output.

What if you want to add an ID to a list item? so instead of this:

Code: Select all

<ul id="happyMenu>
   <li class="item23">
      <a><span></span></a>
   </li>
   <li class="item5">
      <a><span></span></a>
      <ul>
          <li class="item54">
            <a><span></span></a>
         </li>
      </ul>
    <li>
</ul>
You can get this:

Code: Select all

<ul id="happyMenu>
   <li class="item23" id="Joy">
      <a><span></span></a>
   </li>
   <li class="item5" id="[* spam *]">
      <a><span></span></a>
      <ul>
          <li class="item54" id="Euphoria">
            <a><span></span></a>
         </li>
      </ul>
    <li>
</ul>
What I'm asking, is if there is a way of doing this so that the admin can set the ID for the list item through the menu item Edit screen:

Image

I asked about this in another forum to see if it could be added to 1.5, but I didn't understand template overrides. I can see overrides are imperative to oust tables from Joomla default output, but what if you want to add customized attributes into the HTML that can only be determined on a case by case basis?

Anyone have any ideas?

I tried to look at mod_mainmenu's php and I can't make heads or tails of it. My programming skills are not muscular, so if anyone can give me the ABC's of doing this I'd be most grateful!

(The real motivation for me is to be able to grab a particular item with javascript's getElementById so I could do a vertical hover accordion menu that displaces all the lists below it, rather than float over, like suckerfish menus do)

I was able to access the element contextually, but would have preferred to use getElementByID as it is less code and more surgical javascript.

I should add that there is no getElementsByClass in javascript, though if anyone has an improvised version of that to share, please let me know!)

On another note, can anyone explain why on earth the Dev Team used the class attribute for unique item id's? The only reason I can think is that classes can be stacked and ID's can't. Is this why?

TIA,

madame philosophe
-madame philosophe

User avatar
samtherobot
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Mon Dec 05, 2005 11:57 pm
Location: London, Ontario
Contact:

Re: Overriding mod_mainmenu output structure

Post by samtherobot » Thu Jan 10, 2008 10:35 pm

Yes I believe this can be done.  However I don't think it is at all easy with this base menu module.

I'm going to dig a little deeper though as I'm still trying to understand it also.  One of the big changes in 1.5 is the MVC methodology is being used.  However I'm wondering if that is true for modules.  When I look at the template file for mod_mainmenu, I find code that I would definitely not classify as view or layout material.  But again it may be that I just don't totally understand what it's doing.

One thing I did discover going through this time is that it is extending the JTree and JNode class with JMenuTree and JMenuNode.  Understanding those objects would definitely go along way to understanding what it's doing.

However if you're looking for something quick and dirty I would suggest looking at the default.php file in the templates folder.  This is where it seems to be manipulating the elements the most.

As far as why they use class instead of ID.  Only situation I could see arising is if you have 2 seperate menus show up on a page both using the same itemid.  If that was placed in an id tag then you'd have 2 menus with the same id which isn't valid.  I haven't really figured out how this works yet in 1.5 as the "use unique itemid" seems to be gone.

dynedain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Wed Aug 24, 2005 7:20 pm
Location: Los Angeles
Contact:

Re: Overriding mod_mainmenu output structure

Post by dynedain » Thu Jan 10, 2008 10:40 pm

Also as far as I can tell, Joomla isn't doing anything to enforce unique IDs... so I assume using class instead of ID is, as samtherobot mentioned, to help prevent generating non-compliant xhtml.

madamep
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Mon Nov 19, 2007 11:27 pm

Re: Overriding mod_mainmenu output structure

Post by madamep » Thu Jan 10, 2008 11:18 pm

Thanks for your prompt replies!

I have tried to look into the /tmpl file and for mod_mainmenu and really don't understand it. I did read your post, but without being a programmer it's hard to know what you mean.

I can do some tinkering with PHP files, but I'm guessing that this is OOP and I just don't understand the structure.

Can you explain what the division of labor is in the mod_mainmenu?

There are basically these files:
  • helper.php
  • index.html
  • legacy.php
  • mod_mainmenu.php
  • mod_mainmenu.xml
  • /tmpl
    • default.php
    • index.html
Can you give me a narrative of what each file does? I'm going to play dumb here, just for anyone else wanting to know.

Then I was reading someplace that the BEEZ template has a bunch of overrides in /beez/html/ to bypass the default table tag generation. Is it possible to just copy all these into my own TEMPLATENAME/html if I am wanting to get rid of any and all the table output?

Unfortunately, there is no mod_mainmenu override in the BEEZ template so I can't look at that for ideas for my original Q.

Thanks for your help,

madame philosophe
-madame philosophe

dynedain
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Wed Aug 24, 2005 7:20 pm
Location: Los Angeles
Contact:

Re: Overriding mod_mainmenu output structure

Post by dynedain » Thu Jan 10, 2008 11:33 pm

Well, mod_mainmenu doesn't generate tables anymore. It does lists instead. Also, mod_mainmenu doesn't follow the usual MVC structure as recommended for Joomla 1.5, which is what led me to start this thread to begin with.

Basically in MVC, the Model part of the module/component is responsible for describing the data structure of the module/component. The Controller part is responsible for accepting and acting upon requests, in essence the "Business Logic" of what the module/component does. The View part is responsible for taking results and handling how they are displayed.

mod_mainmenu does not follow this methodolgy at all and instead opts for taking the menus from the database, building an XML structure out of them, and then dumping that XML structure as the output that is displayed. Because there is no real templating going on, it's very difficult to override the "View" or output code part of the module.

Clear as mud right?

madamep
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Mon Nov 19, 2007 11:27 pm

Re: Overriding mod_mainmenu output structure

Post by madamep » Thu Jan 10, 2008 11:49 pm

Hi dynedain,

The MVC model makes a lot of sense.

But since mod_mainmenu doesn't use this approach, what can be done for us?

Can we write our congressman? riot? beg and plead?

I'm wondering if they did this for optimizing return time. If that's the case, it's understandable, but there should be a way to customize to generate your own HTML template even if it is editing the XML template.

In a way there is templating of some kind going on because the links from the db are getting inserted into a ul list.

What would be ideal is if to create your own html template for your list and also be able to add attributes in the admin backend, as I've belabored a few times now.

Can you show me to how the XML structure is created? Or do you know?

Best,

madame p
-madame philosophe

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: Overriding mod_mainmenu output structure

Post by CirTap » Wed Jan 16, 2008 9:03 pm

Hi,

mod_mainmenu does follow the MVC model, it just doesn't use the same type of "html file" interrupted with stuff, but does all it's magic inside a single function.

In order to override mainmenu you need a copy of
/modules/mod_mainmenu/tmpl/default.php
and drop it into
/templates/your_tpl/html/mod_mainmenu/default.php

Then rename all "modMainMenuXMLCallback" to your own fancy name, ie. "mySpecialMainMenu"
the related lines/code:
  if ( ! defined('modMainMenuXMLCallbackDefined') )
  define('modMainMenuXMLCallbackDefined', true);

  function modMainMenuXMLCallback(&$node, $args)
  modMainMenuHelper::render($params, 'modMainMenuXMLCallback');

save and test your changes.

Then you can go ahead and change the PHP code of your (new) function mySpecialMainMenu(...) to rearrange the XML nodes to suit your needs, add or drop class and id attributes and do other dirty things.
Dealing with an "XML DOM" requires a lot of code, travelling up/down the object tree, the children and attribute collections. Just don't waste your time looking at JTree and JNode: the mainmenu is built from another beast - JSimpleXMLElement located in /libraries/joomla/utilities/simplexml.php

For those who'd like to use the "alias" in the class attribute, here's a chunk of code I used in "my special main_menu" :)
Add this right at the top of the function, and you'll get an array $aliases indexed by menu-item ID with a bunch of properties for later use.
[php]
...
$path = isset($active) ? array_reverse($active->tree) : null;

// get aliases and such from the menu items
$_items  = $menu->getMenu();
$aliases = array();
foreach ($_items as $_i) {
    if ($_i->published) {
        $aliases[$_i->id] = array(
                'menutype'=> $_i->menutype,
                'name'    => $_i->name,
                'alias'  => $_i->alias
                );
    }
}
unset($_items,$_i); // clean up

if (($args['end']) ...
[/php]

here's the part where I add the "alias" to the LI item's class attribute:
[php]
    if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
        $css = $node->attributes('class');
        if (isset($aliases[ $id ])) {
            $node->addAttribute('class', trim($css.' '.$aliases[ $id ]['alias']) );
        } else {
            $node->addAttribute('class', trim($css.' item'.$id) );
        }
    }
[/php]

Hope this helps to get you started.

Have fun,
CirTap

.. edit: fixed some typos
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

User avatar
ivanicus
Joomla! Intern
Joomla! Intern
Posts: 72
Joined: Fri Jul 06, 2007 6:15 am
Location: Havana City, Cuba
Contact:

Re: Overriding mod_mainmenu output structure

Post by ivanicus » Mon Jan 21, 2008 2:54 pm

Thanks CirTap!!!

Quite helpful answer!!!

Still we see that programming knowledge is requiered to mingle with the menu overrides, but hey! Most of overrides already have that need ;-)

Thanx!
Free speech for the dumb!

richid
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Fri Dec 14, 2007 3:53 am
Location: CA

Re: Overriding mod_mainmenu output structure

Post by richid » Wed Feb 06, 2008 9:11 am

Has anyone had problems with mod_mainmenu in regards to access restricted menus which causes the nested lists to break?

Here is my problem:  I have a menu item X that is accessible to everyone on the site.  Under that, I have 3 children menu items, X1-X3 that are only accessible to a certain user group.  If you click on the world-accessible parent item X, none of restricted menu items show up, as expected.  However, the next world-accessible menu item Y, which is at the same level as X, is indented as if it is a child of X.  I've checked the HTML, and this is caused by an extra thrown in after X.  After digging around in modules/mod_mainmenu/helper.php and modules/mod_mainmenu/tmpl/default.php for a while  I've come to the following conclusion:  It seems that if you remove all of a parents children it doesn't remove starting tag like it should, so you're left with an orphaned open tag.

Does that make sense?  I'm hoping someone can chime in that has more experience with this than I.  I've got a pretty ugly hack going in the JSimpleXMLElement classes toString method, but I would much rather solve this in the default.php file, as it can be overridden in your template negated the need to hack a core file.

Cheers!

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: Overriding mod_mainmenu output structure

Post by CirTap » Wed Feb 06, 2008 12:09 pm

Hi,

it probably "makes sense" that mod_mainmenu behaves like this, nonetheless it is indeed wrong behaviour and either the SQL query or the modMainMenu function should care about this. I'd consider this a bug in the menu rendering function: it still has the information that item X could potentionally have child items, so it starts adding a . Unfortunately there are no children to render the items for and the is closed -- because the output is created by an XML parser, this translates to
An empty is not allowed in (X)HTML and the browser believes the "/" is just an unknown (xml-)attribute without a value; it open the list and *renders* the subsequent items as a nested list.

If you have an account @ joomlacode.org you should file a tracker item, or ask a mod ("Report this post") to move your "bug report" to the "Bug squashing" forum, 'cos I believe it won't be seen by the devs if it stays here :-)

Have fun,
CirTap
Last edited by CirTap on Wed Feb 06, 2008 12:10 pm, edited 1 time in total.
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

richid
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Fri Dec 14, 2007 3:53 am
Location: CA

Re: Overriding mod_mainmenu output structure

Post by richid » Wed Feb 06, 2008 5:24 pm

CirTap wrote: If you have an account @ joomlacode.org you should file a tracker item, or ask a mod ("Report this post") to move your "bug report" to the "Bug squashing" forum, 'cos I believe it won't be seen by the devs if it stays here :-)
Thanks for the response CirTap.

I'm working on the fix right now and hope to submit a patch in a day or so using the bug tracker at Joomlacode.  When you say the "Bug squashing" forum are you referring to Joomla! 1.5.x_Q&T forum?

User avatar
CirTap
Joomla! Explorer
Joomla! Explorer
Posts: 418
Joined: Mon Dec 12, 2005 5:34 pm

Re: Overriding mod_mainmenu output structure

Post by CirTap » Wed Feb 06, 2008 5:30 pm

richid wrote:When you say the "Bug squashing" forum are you referring to Joomla! 1.5.x_Q&T forum?
yes, this one http://forum.joomla.org/index.php/board,199.0.html
You can have programs written fast, well, and cheap, but you only get to pick 2 ...

"I love deadlines. I like the whooshing sound they make as they fly by." Douglas Adams

arlen
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Fri Dec 08, 2006 7:01 pm

Re: Overriding mod_mainmenu output structure

Post by arlen » Fri Feb 08, 2008 6:54 pm

richid wrote: I'm working on the fix right now and hope to submit a patch in a day or so using the bug tracker at Joomlacode.  When you say the "Bug squashing" forum are you referring to Joomla! 1.5.x_Q&T forum?
In that case I'll take it off my list. I had run into the same bug, but it wasn't a high priority for me because I don't have any empty menus published. But since you're going to tackle it, I'll take it off my list and spend that time on some other bugs.

richid
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Fri Dec 14, 2007 3:53 am
Location: CA

Re: Overriding mod_mainmenu output structure

Post by richid » Sat Feb 09, 2008 8:24 pm

arlen wrote: In that case I'll take it off my list. I had run into the same bug, but it wasn't a high priority for me because I don't have any empty menus published. But since you're going to tackle it, I'll take it off my list and spend that time on some other bugs.
Well, I've got a hack going that fixes the problem, but it is nowhere near elegant.  I've left the bug open in Joomlacode, as I know there is a much cleaner solution for this.  Thing is, I'm under a tight deadline from a client so I am unable to spend time to track this down and squash it right now.  Plus, I feel like the whole menu system is really convoluted and could be made much simpler and faster.

arlen
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Fri Dec 08, 2006 7:01 pm

Re: Overriding mod_mainmenu output structure

Post by arlen » Mon Feb 11, 2008 3:49 pm

richid wrote: Plus, I feel like the whole menu system is really convoluted and could be made much simpler and faster.
Amen, brother.  ;D

Seriously, I keep running into this same phenomenon. "x in Joomla works like this except....." 1.5 is an improvement, certainly. But we ain't there, yet. Not while the list of "except....." is so long.

Still, the road may be long but we're moving in the right direction.

richid
Joomla! Apprentice
Joomla! Apprentice
Posts: 25
Joined: Fri Dec 14, 2007 3:53 am
Location: CA

Re: Overriding mod_mainmenu output structure

Post by richid » Mon Feb 11, 2008 8:40 pm

arlen wrote: Seriously, I keep running into this same phenomenon. "x in Joomla works like this except....." 1.5 is an improvement, certainly. But we ain't there, yet. Not while the list of "except....." is so long.
From what I've seen, 1.5 is a huge improvement, so definitely kudos to the dev team.  This is a pretty large project and is run mostly by volunteers, so it's understandable that the turnaround time isn't lightning quick.

The one thing I'm confused about: why use XML in the menu system?  It just seems to duplicate and complicate the entire process way too mucuh.

arlen
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 215
Joined: Fri Dec 08, 2006 7:01 pm

Re: Overriding mod_mainmenu output structure

Post by arlen » Mon Feb 11, 2008 9:22 pm

richid wrote: The one thing I'm confused about: why use XML in the menu system?  It just seems to duplicate and complicate the entire process way too mucuh.
I  was never able to figure out if the question should be that or "why not use XML in the rest of the system?"

On the one hand, using XML is a bit more complex, but on the other, using XML opens the way to a whole lot of interesting options by way of Xpath, XSLT, and such.

Imagine, if you will, the requested page getting assembled in XML and then rendered via XSLT into many different formats based on parameters including, for example, the fact that the "browser" is a cell phone. The mind boggles, but the imagination salivates.

Kinds puts template overrides to shame, doesn't it?  ;D

(Hmm....I wonder if you could actually use template overrides to create a proper XML file of the content? Stop it. Put the keyboard down and step away from the computer. Now.)

guyo
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Wed Oct 31, 2007 3:20 pm

Re: Overriding mod_mainmenu output structure

Post by guyo » Fri Feb 15, 2008 3:39 pm

as a coding lightweight, I got stumped halfway through CirTap's explanation,
could anyone help with suggesting which files I could add some css to make a vertically expanding menu, or helping understand the order in which the files are referenced, like er...

who's on first, what's on second

thanks

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 Feb 25, 2008 5:01 pm

My colleague and I have played with joomla 1.5 mod_mainmenu module today, trying to override default XML tree management and output.
We have a problem to manage separators in joomla 1.5 horizontal menu ( http://forum.joomla.org/viewtopic.php?f ... &p=1215185 ). Probably further work is needed, but as a good beginning we have hacked default.php to control what list items are the first and last child of a list.

After moving /modules/mod_mainmenu/tmpl/default.php to /templates/template_name/html/mod_mainmenu/ we have customized it as you can see in the result file attached to this post.

Summarizing we have introduced a global variable $item_per_level_counter to count menu items and add an additional CSS class "fistItem" to first element of every li set on a per level basis, resetting items counter for every level.
A reference to parent item is kept, too, for identifying the last item and adding "lastItem" class.

Any comment is welcome to improve the code and reach other goals as to have more control on output structure.

Hope this can help.
You do not have the required permissions to view the files attached to this post.
--
Marco Giorgetti :: http://www.marcogiorgetti.com

doonee
Joomla! Intern
Joomla! Intern
Posts: 55
Joined: Wed Apr 18, 2007 8:51 pm

Re: Overriding mod_mainmenu output structure

Post by doonee » Sat Mar 15, 2008 10:53 pm

hi all....

I guess it'd be well within the ballpark to use these override approaches to have mainmenu ouput the 'Alias' field -the one right under the menu item name field in the 1.5 menu manager- as the title attribute of a menu item link, correct ?
pretty cool .. :)
has anyone done this ?

cheers
d

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 1:34 am

midimarcus,

Just wanted to say thanks for posting your modified default.php. I was trying to do the exact same thing and you saved me a lot of time. It worked perfect.

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 1:58 am

jazbek wrote:It worked perfect.
Good news! :D

Please, if you make some other improvements post your modified files it in this forum.


Locked

Return to “Templates for Joomla! 1.5”