Why the Liferay developers doesn't done it, i don't know but if you create several submenus you will see only first submenu level.
#if ($nav_item.hasChildren())
<ul class="child-menu">
#foreach ($nav_child in $nav_item.getChildren())
#if ($nav_child.isSelected())
<li class="selected">
#else
<li>
#end
<a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
</li>
#end
</ul>
#end
As we can see this template can print only first submenu level. Lets add recursive macro to print all sub menu levels. Here is our macro:
#macro( printSubMenu $children )
<ul class="child-menu">
#foreach( $child in $children )
#if ($child.isSelected())
<li class="selected">
#else
<li>
#end
<a href="$child.getURL()" $child.getTarget()>$child.getName()</a>
#if ($child.hasChildren())
// If a child has a child also print out them
#printSubMenu($child.getChildren())
#end
#end
</ul>
#end
All we need now is use it in our navigation.vm file in proper place:
...
// All children must use printSubMenu macro
#if ($nav_item.hasChildren())
#printSubMenu($nav_item.getChildren())
#end
Now all submenus levels will be on result html page (you can check page source code in your browser), but it's not all, you can't see them properly because of css submenu styles that hides these elements. You must fix it in your theme.
The reason is simple. Just look at navigation.vm file snippet:
#if ($nav_item.hasChildren())
<ul class="child-menu">
#foreach ($nav_child in $nav_item.getChildren())
#if ($nav_child.isSelected())
<li class="selected">
#else
<li>
#end
<a href="$nav_child.getURL()" $nav_child.getTarget()>$nav_child.getName()</a>
</li>
#end
</ul>
#end
As we can see this template can print only first submenu level. Lets add recursive macro to print all sub menu levels. Here is our macro:
#macro( printSubMenu $children )
<ul class="child-menu">
#foreach( $child in $children )
#if ($child.isSelected())
<li class="selected">
#else
<li>
#end
<a href="$child.getURL()" $child.getTarget()>$child.getName()</a>
#if ($child.hasChildren())
// If a child has a child also print out them
#printSubMenu($child.getChildren())
#end
#end
</ul>
#end
All we need now is use it in our navigation.vm file in proper place:
...
// All children must use printSubMenu macro
#if ($nav_item.hasChildren())
#printSubMenu($nav_item.getChildren())
#end
Now all submenus levels will be on result html page (you can check page source code in your browser), but it's not all, you can't see them properly because of css submenu styles that hides these elements. You must fix it in your theme.
Комментариев нет:
Отправить комментарий