Download
We're evolving to serve you better! This current forum has transitioned to read-only mode. For new discussions, support, and engagement, we've moved to GitHub Discussions.

{{menuItemClasses}} helper not working correctly?

  • #10478
    Avatar photo[anonymous]

    The page at https://getpublii.com/dev/menuitemclasses-helper/ shows the option to add classes to this helper for example:

    {{menuItemClasses "active"}}

    But when I try this out the active class does not appear to be inserted in the rendered website, am I doing something incorrect?

    #10480
    Avatar photoBob

    Describe more details, and let us know the complete menu code.

    #10483
    Avatar photo[anonymous]

    I have a custom menu.hbs file and my bootstrap theme needs a “nav-item” class on each menu item. Then I wanted to be able to use a custom class on each nav-item that I could insert through the Publii dashboard.

    <ul class="navbar-nav">
    
       {{! loop generating a list of menu items}}
       {{#each items}}
          <li {{menuItemClasses "nav-item"}}>
    
          {{! check if the menu item is a link }}
          {{#if link}}
             <a
                href="{{menuUrl}}"
    
                {{! check if title attribute exists }}
                {{#if title}}
                   title="{{title}}"
                {{/if}}
                {{! /check if title attribute exists }}
    
                {{! check if target attribute exists }}
                {{#if target}}
                   target="{{target}}"
                {{/if}}
                {{! /check if target attribute exists }}
    
                {{! check if rel attribute exists }}
                {{#if rel}}
                   rel="{{rel}}"
                {{/if}}
                {{! /check if rel attribute exists }}
    
                {{! check if the menu item contains a submenu }}
                {{#if items}}
                   aria-haspopup="true"
                {{/if}} class="nav-link">
                {{! /check if the menu item contains a submenu }}
    
                {{label}}
             
             {{! /check if the menu item is a link }}
    
          {{else}}
             {{! if the menu item is not a link display a separator }}
             <span
                {{#if title}}
                   title="{{title}}"
                {{/if}}
                {{#if items}}
                   aria-haspopup="true"
                {{/if}}>
                {{label}}
             </span>
             {{! if the menu item is not a link display a separator }}
          {{/if}}
    
          {{! check if the menu item contains a submenu }}
          {{#if items}}
             {{> menu}}
          {{/if}}
          {{! check if the menu item contains a submenu }}
    
       
       {{/each}}
       {{! /loop generating a list of menu items}}
    
    
    
    #10484
    Avatar photo[anonymous]

    I decided to just use the :nth-child() pseudo selector in my stylesheet to color each individual menu item instead of adding the color class in Publii like I originally tried to do. I also ended up using the menu classes to set a font icon to each menu item for example: <i {{menuItemClasses}}></i>