Menu¶
A Selection
is an easy solution to building a navigation menu.
Steps¶
- Add an ‘in_nav’ attribute to pages you want to appear in the menu.
- Create a
Selection
in yourcontent
directory. - Add it to your template.
1. Add attributes¶
in_menu: True
---
Some page!
2. Create a Selection
¶
Add the selection
plugin to config.yml
:
plugins:
- gilbert.plugins.selection
Next, add a menu object to your content
directory:
content_type: Selection
filter_by:
- attr: ['in_menu']
This filter will select any object with the in_menu
attribute having a
“truthy” value.
3. Add it to your template¶
Finally you can add something like the following to render your menu in your page:
<ul>
{% for page in site.content['menu.yml'].pages %}
<li><a href="{{ page.url }}">{{ page.title }}</a></li>
{% endfor %}
</ul>
Added features¶
Instead of setting in_menu
to True, you could assign a value and order
by it to ensure consistent ordering.
content_type: Selection
filter_by:
- attr: ['in_menu']
sort_by: in_menu