Jahia in English > menu which displays...

0 (0 Good)
0 (0 Bad)

menu which displays only child nodes of selected menu item

by  muristan »  2014/08/16 15:31

I put just one vertical menu on the left for all my website. Actually all the second level menu items are displayed for all the first level menu items.

I just want displayed the second level menu item of the selected first level menu item.

I now I have copy jahia6.6.2/tomcat/webapps/ROOT/modules/default/jnt_navMenu/html/navMenu.groovy to jahia6.6.2/tomcat/webapps/ROOT/modules/myTemplate/jnt_navMenu/html/navMenu.groovy and to modify it.

What code lines must be changed in navMenu.groovy to display only the child nodes of selected menu item??


Number of messages  25
Registration date
0 (0 Good)
0 (0 Bad)

Re: menu which displays only child nodes of selected menu item

by  vagarwal »  2015/04/23 07:05


You will need to override the default view code for navigation menu to hide/show the menu childs, and use this custom view from your template set, when adding the nav menu module to your template design.



In your template set, add the jnt_navMenu/html folder, and then create two files, "navMenu.someMenuName.groovy.html" and "navMenu.someMenuName.properties"



Properties to contain : 





In the groovy file, copy the original code from module source for jnt_navMenu from defaultXXX.jar, and add the code in bold, basically, try to see if a menu or one of its child ( in case of multilevel menu ) was selected, if yes then only select the child, else not.

Groovy is like Java, feel free to add your logic or a better way to hide/show based on your custom requirement.

Original code for me in : \Jahia-DigitalFactory7-SDK\tomcat\webapps\ROOT\WEB-INF\var\modules\default-\jnt_navMenu\html\navMenu.groovy


foundAChildSelected = false
def hasAChildSelected(node){

     if (node) {
          children = JCRContentUtils.getChildrenOfType(node, "jmix:navMenuItem")
          children.eachWithIndex() { menuItem, index ->
            itemPath = menuItem.path;
            if(renderContext.mainResource.node.path == itemPath){
               foundAChildSelected = true;
            children = JCRContentUtils.getChildrenOfType(menuItem, "jmix:navMenuItem")
            def nbOfChilds = children.size();
            if(nbOfChilds > 0){
          }//child ends
     }//if ends
}//method ends



                       print render
                        // end template:module
                    if (hasChildren) {

                    if(selected || foundAChildSelected){
                            foundAChildSelected = false;
                            printMenu(menuItem, navMenuLevel + 1, true)

//                    print "<li>"
//                    printMenu(menuItem, navMenuLevel + 1, true)
//                    print "</li>"
                    if (render != "") {
                        print "</li>"





Finally use this 'someMenu' in the view, when you drop a navigation menu on your template in the 'Layout' tab of dropped 'navigation menu' component, under View section.



Number of messages  1
Registration date

Get in touch

Whether you are a current user or if you are just evaluating Jahia, we are here to help.

Contact us

Share this page