Joomla exit html main menu

I am trying to edit the joomla main_menu output module so that I can create a custom drop-down menu. At the moment, it outputs html as follows:

<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 output.

I know that if I want to edit the output; in my template folder I create a directory called "html" and then inside this new directory with the name "mod___mainmenu" and then make a copy of the default.php file from the existing mod_mainmenu folder from the modules directory. All changes made to the file will change.

The problem I am facing is that I cannot understand what is happening with the code written in the default.php file, because it uses some XML system that I disagree with, and there are no comments.

If anyone has ideas that would be very 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'); 
+4
source share
2 answers

It turns out that span tags are being added to a completely different file.

If you go to the modules / mod_mainmenu directory, the helper.php file appears, which also controls part of the output.

Lines 285 and 293 have span tags in the code. Removing those that made the exit works the way I wanted it to.

+2
source

You should avoid editing core files whenever possible to avoid changing your changes when updating. Use template override files instead.

When I came across this, I wanted to add and remove the em tag for each menu item to allow the replacement of Gilder / Levin images . In my html override ({templatedir} \ html \ mod_mainmenu \ default.php) I surrounded the call to modMainMenuHelper :: render (the last line, basically) with the 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 can do:

 ob_start(); modMainMenuHelper::render($params, 'modMainMenuXMLCallback'); $mainMenuContent = ob_get_clean(); echo str_replace(array('<span>','</span>'), array('',''), $mainMenuContent); 
+6
source

All Articles