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.

Question about submenu

  • #3162
    Avatar photo[anonymous]

    I am checking the menu partial, what is the return value of {{#unless level}} ? I cannot find “level” in the doc.

    https://getpublii.com/dev/menuhbs-partial/

    <code class=" language-handlebars"><span class="token handlebars language-handlebars"><span class="token delimiter punctuation">{{</span><span class="token block keyword">#unless</span> <span class="token variable">level</span><span class="token delimiter punctuation">}}</span></span>
    #3173
    Avatar photoBob

    {{#unless}} is the opposite of {{#if}}. So if we want to exclude <nav> element from the submenus (it wouldn’t be semantic) we should use the {{#unless level}} helper for that:

    {{#unless level}}
    <nav>
    {{/unless}}
        <ul{{#if level}} class="submenu submenu-level-{{level}}"{{else}} class="menu menu-level-1"{{/if}}>
            {{#each items}}
                <li{{menuItemClasses}}>
                {{#if link}}
                <a href="{{menuUrl}}"{{#if title}} title="{{title}}"{{/if}}{{#if target}} target="{{target}}"{{/if}}{{#if rel}} rel="{{rel}}"{{/if}}>{{label}}</a>
                {{else}}
                <span{{#if title}} title="{{title}}"{{/if}}>{{label}}</span>
                {{/if}}
    
                {{#if items}}
                    {{> menu}}
                {{/if}}
            </li>
            {{/each}}
        </ul>
    {{#unless level}}
    </nav>
    {{/unless}}
    

    in short: if your menu generates submenus (more levels) the nav container will be used only one.