Generate a flat navigation using the default page array.

{% raw %}{{ pages | navigation }}{% endraw %}
{{ pages | navigation }}

Generate a nested navigation using the nested array.

{% raw %}{{ nested_pages | navigation }}{% endraw %}
{{ nested_pages | navigation }}

The html structure and the css classes allows styling current page, active parent pages, naked directories, getting pages by name, etc. to build any type of navigation : dropdown menus, single-lined breadcrumbs...

{% raw %}.is-page, .is-directory, .is-current, .is-active, .has-childs ...{% endraw %}

Filtering pages paths with the exclude filter :

{% raw %}{{ nested_pages | exclude('PicoPagesList') | navigation }}{% endraw %}
{{ nested_pages | exclude('PicoPagesList') | navigation }}

Filter the inner pages by using a trailing slash :

{% raw %}{{ nested_pages | exclude('PicoPagesList/') | navigation }}{% endraw %}
{{ nested_pages | exclude('PicoPagesList/') | navigation }}

Filter all pages except the given ones with only, and chain filters :

{% raw %}{{ nested_pages | only('PicoPagesList') | exclude('PicoPagesList/sub/bar') | navigation }}{% endraw %}
{{ nested_pages | only('PicoPagesList') | exclude('PicoPagesList/sub/bar') | navigation }}

Filters can be given multiple paths :

{% raw %}{{ nested_pages | only('PicoPagesList/sub', 'index') | navigation }}{% endraw %}
{{ nested_pages | only('PicoPagesList/sub', 'index') | navigation }}

Custom loop :

{% raw %}{% macro menu(items) %} <ul> {% for name,item in items %} <li> {% if item.url %} <a href="{{ item.url }}">{{ item.title }}</a> : {{ item.description }} {% else %} <span>{{ name }}</span> {% endif %} {% if item._childs %} {% import 'macros.twig' as macros %} {{ macros.menu(item._childs) }} {% endif %} </li> {% endfor %} </ul> {% endmacro %}{% endraw %} {% raw %}{% import 'macros.twig' as macros %} {{ macros.menu(nested_pages) }}{% endraw %}
{% macro menu(items) %}
    {% for name,item in items %}
  • {% if item.url %} {{ item.title }} : {{ item.description }} {% else %} {{ name }} {% endif %} {% if item._childs %} {% import _self as macros %} {{ macros.menu(item._childs) }} {% endif %}
  • {% endfor %}
{% endmacro %} {% import _self as macros %} {{ macros.menu(nested_pages) }}