Sophisticated, Lightweight and Simple

Jump to docs navigation
Edit on GitHub

Howtos ยป Creating a simple menu

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/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.

Couldn't find what you were looking for? We are happy to help you in the forum, on Slack or on IRC.
Spotted a typo, or have something to add? Edit this page on GitHub.