Note that there are some explanatory texts on larger screens.

plurals
  1. POModifying Joomla Main Menu's submenu using template override
    primarykey
    data
    text
    <p>I would like to achieve the following in my Joomla template's main menu:</p> <pre><code> &lt;ul class="topmenu"&gt; &lt;li&gt;&lt;a class="nav_link" id="active" href="#"&gt;Home&lt;/a&gt;&lt;/li&gt;&lt;span class="separator"&gt;&lt;/span&gt; &lt;li&gt;&lt;a class="nav_link" href="#"&gt;About Us&lt;/a&gt;&lt;/li&gt;&lt;span class="separator"&gt;&lt;/span&gt; &lt;li&gt;&lt;a class="nav_link" href="#"&gt;Services&lt;/a&gt; &lt;div class="subnav_wrapper"&gt; &lt;ul class="subnav"&gt; &lt;li&gt;&lt;a class="sub_nav_link" href="#"&gt;Custom Software&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="sub_nav_link" href="#"&gt;Software Solutions&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="sub_nav_link" href="#"&gt;Mobile SMS&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a class="sub_nav_link" href="#"&gt;Web Solutions&lt;/a&gt;&lt;/li&gt; &lt;li class="last"&gt;&lt;a class="sub_nav_link" href="#"&gt;ICT Consultancy&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/li&gt;&lt;span class="separator"&gt;&lt;/span&gt; &lt;/ul&gt; </code></pre> <p>I've already overriden the default.php file for the module (I've copied "default.php" from "modules\mod_mainmenu\tmpl" into "templates\mytemplate\html\mod_mainmenu". What I don't get is how I can differentiate between the top-level ul, li and a elements and those in the subnav. For example, to add the class "last" to the last list item in the subnav, I've tried the following:</p> <pre><code>if ($node-&gt;name() == 'ul') { foreach ($node-&gt;children() as $child) { if ($child-&gt;attributes('access') &gt; $user-&gt;get('aid', 0)) { $node-&gt;removeChild($child); } } $children_count = count($node-&gt;children()); $children_index = 0; foreach ($node-&gt;children() as $child) { if ($children_index == $children_count - 1) { $child-&gt;addAttribute('class', 'last'); } $children_index++; } } </code></pre> <p>But the above adds the class also in the last item of the top-level ul. </p> <p>Is a way to achieve the desired effect using the template override method?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload