navbarMenu.vm 1.9 KB
#macro( displayNavbarMenu $menu $count)
  #if ($displayer.isAllowed($menu))
    #set ($count = $count + 1)
    ## set menu title
    #set ($title = $displayer.getMessage($menu.title))
    #if (!$menu.url) #set ($url="javascript:void(0)") #else #set ($url=$menu.url) #end

    ## create a single menu item
    #if ($menu.components.size() == 0)
        <li class="#if ($menu.name == $currentMenu)active#end">
        <a href="$url" title="$title" #if($menu.target)target="$menu.target" #end#if($menu.width)style="width: ${menu.width}px"#end>${title}</a>
    #else ## create multiple menu items in a menu
        #if ($menu.components.size() > 0)
            #set ($hasViewableChildren = false)
            #set ($renderedChildren = 0)
            #foreach ($menuIt in $menu.components)
                #if ($displayer.isAllowed($menuIt))
                    #set($hasViewableChildren = true)
                    #set($renderedChildren = $renderedChildren + 1)
                #end
            #end
        #end

        <li#if ($hasViewableChildren) class="dropdown#if ($menu.name == $currentMenu) active#end"#end>
          <a href="#" title="$title"
             #if($menu.target)target="$menu.target" #end
             #if($menu.width)style="width: ${menu.width}px"#end
             class="dropdown-toggle" data-toggle="dropdown">${title}</a>
    #end

    #if ($menu.components.size() > 0)
        #if ($hasViewableChildren)
          <ul class="dropdown-menu">
        #end

        #set ($count = 0)
        #foreach ($menuIt in $menu.components)
            #displayNavbarMenu($menuIt, $count)
        #end

        #if ($hasViewableChildren && ($count == $renderedChildren))
          </li>
        #else
          </ul>
          #if ($count > $renderedChildren)
          </li>
          #end
        #end
    #else
      </li>
      #if ($menu.parent && $count == $menu.parent.components.size())
      </ul>
      #end
    #end
  #end
#end

#displayNavbarMenu($menu, 0)