I'm trying to edit the output joomla main_menu module so I can make a custom dropdown menu. At the moment it currently outputs html like this:
<ul class="menu">
<li class="active item1" id="current"><a href="#"><span>First Level Item </span</a></li>
<li class="parent item63"><a href="#"><span>First Level Item Parent</span></a>
<ul>
<li class="item60"><a href="#"><span>Second Level Item</span></a></li>
<li class="item69"><a href="#"><span>Second Level Item</span></a></li>
</ul>
</li>
<li class="item64"><a href="#"><span>First Level Item</span></a></li>
<li class="item66"><a href="#"><span>First Level Item</span></a></li>
What I would like to do is remove the span tags for the output.
What I know so far is that if I want to edit the output; in my template folder I make a directory called 'html' and then inside that a new directory called 'mod___mainmenu' and then a make copy the default.php file from the existing mod_mainmenu folder from the modules directory. All the changes to I make to take file will change the output.
The problem that I'm having is that I can't understand what is happening with the code that is written in the default.php file as it use some XML system that I'm unfamilar with and there are no comments.
If anyone has any ideas that would be super helpful!
Here is the code from the default.php file for the menu:
defined('_JEXEC') or die('Restricted access');
if ( ! defined('modMainMenuXMLCallbackDefined') )
{
function modMainMenuXMLCallback(&$node, $args)
{
$user = &JFactory::getUser();
$menu = &JSite::getMenu();
$active = $menu->getActive();
$path = isset($active) ? array_reverse($active->tree) : null;
if (($args['end']) && ($node->attributes('level') >= $args['end']))
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
if ($node->name() == 'ul') {
foreach ($node->children() as $child)
{
if ($child->attributes('access') > $user->get('aid', 0)) {
$node->removeChild($child);
}
}
}
if (($node->name() == 'li') && isset($node->ul)) {
$node->addAttribute('class', 'parent');
}
if (isset($path) && in_array($node->attributes('id'), $path))
{
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' active');
} else {
$node->addAttribute('class', 'active');
}
}
else
{
if (isset($args['children']) && !$args['children'])
{
$children = $node->children();
foreach ($node->children() as $child)
{
if ($child->name() == 'ul') {
$node->removeChild($child);
}
}
}
}
if (($node->name() == 'li') && ($id = $node->attributes('id'))) {
if ($node->attributes('class')) {
$node->addAttribute('class', $node->attributes('class').' item'.$id);
} else {
$node->addAttribute('class', 'item'.$id);
}
}
if (isset($path) && $node->attributes('id') == $path[0]) {
$node->addAttribute('id', 'current');
} else {
$node->removeAttribute('id');
}
$node->removeAttribute('level');
$node->removeAttribute('access');
}
define('modMainMenuXMLCallbackDefined', true);
}
modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
You should avoid editing core files whenever possible to avoid having your changes overwritten when you upgrade. Use template override files instead.
When I ran into this, I wanted to add and empty em tag to each menu item to allow for Gilder/Levin image replacement. In my html override ({templatedir}\html\mod_mainmenu\default.php) I surrounded the call to modMainMenuHelper::render (the last line, basically) with an output buffer, and used a simple str_replace to add the em tag:
ob_start();
modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
$mainMenuContent = ob_get_clean();
echo str_replace('</span>', '</span><em></em>', $mainMenuContent);
Since you just want to get rid of the span tag, you could do:
ob_start();
modMainMenuHelper::render($params, 'modMainMenuXMLCallback');
$mainMenuContent = ob_get_clean();
echo str_replace(array('<span>','</span>'), array('',''), $mainMenuContent);
It turns out that the span tags are added in a completely different file.
If you go to modules/mod_mainmenu directory there is a helper.php file that also controls some of the output.
On lines 285 and 293 there are some span tags in the code. Deleting those made the output work the way that I wanted it to.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With