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}}