Usage: {{navigation}}
and {{navigation type="secondary"}}
{{navigation}}
is a template-driven helper which outputs formatted HTML of menu items defined in the Ghost admin panel (Settings > Design > Navigation). By default, the navigation is marked up using a preset template.
There are two types of navigation, primary and secondary, which you can access using {{navigation}}
and {{navigation type="secondary"}}
.
{{navigation}}
in your theme, looks like the following:
./partials/navigation.hbs
. If this file exists, Ghost will load it instead of the default template. Example:
navigation.hbs
will overwrite both the main navigation as and secondary navigation. To customise the secondary navigation differently use the {{#if isSecondary}}...{{/if}}
helper. Example:
./partials/navigation.hbs
template file…
about-us
. Can be used as a class to target specific menu items with CSS or jQuery.{{#foreach navigation}}
loop inside ./partials/navigation.hbs
. A navigation loop will not work in other partial templates or theme files.
{{#if}}
statement to prevent an empty list. However, it’s a common pattern to want to output a link to open the main menu, but only if there are items to show.
The data used by the {{navigation}}
helper is also stored as a global variable called @site.navigation
. You can use this global variable in any theme file to check if navigation items have been added by a user in the Ghost admin panel.