Edit on GitHub
Jump to docs navigation

HOWTOs / Creating a simple menu

Note: You are currently reading the documentation for Bolt 4.0. Looking for the documentation for Bolt 5.2 instead?

The following creates a simple menu in HTML, based on the last 4 pages. Only pages where the chapter taxonomy is 'main' are selected, assuming there's a taxonomy 'chapter'.

    <nav id="main">
    {% setcontent pages = 'pages' latest limit 4 where { 'taxonomy/chapter': 'main'}  %}

    {% for page in pages %}
        {% if loop.first %}<ul>{% endif %}
        <li><a href="{{ page|link }}" {% if page|current %}class="current"{% endif %}>{{ page.title|trimtext(12) }}</a></li>
        {% if loop.last %}</ul>{% endif %}
    {% else %}
        <em>No main navigation items. Add some Pages, and set the 'Chapter' to 'Main'.</em>
    {% endfor %}

Note: This is a specific sample. In general, you're probably better off using Bolt's built in menu functionality.

Edit this page on GitHub
Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on Github.