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