Skip to content

Instantly share code, notes, and snippets.

@sbonardt
Last active September 26, 2016 18:50
Show Gist options
  • Save sbonardt/d7420f3e8aebb553e0e9 to your computer and use it in GitHub Desktop.
Save sbonardt/d7420f3e8aebb553e0e9 to your computer and use it in GitHub Desktop.
{#
Name: bolt-taxonomy-navigation.twig
Description: Defining taxonomy categories and using them as navigation in Bolt. Only print out those with records assigned to them
Author: S. Bonardt
CMS: Bolt CMS - Bolt.cm
Define the categories like below in taxonomy.yml, using key and value (under 'options') i.s.o. default way. E.G:
categories:
name: Categories
slug: categories
singular_name: Category
singular_slug: category
behaves_like: categories
multiple: true
options:
key1: Value 1
lorem: Lorem ipsum dolor
testkey: Test-key
listing_template: customcategory-listing.twig
#}
{#
if you like you can dump the taxonomy for debugging like this:
print(config.get('taxonomy/categories/options'))
#}
<ul class="categories">
{% set active = app.request.get('_route_params').slug -%}
{% for key, category in config.get('taxonomy/categories/options') %}
{% setcontent categoryrecords = 'records' where { categories: key } %}
{% if categoryrecords|length > 0 %}
<li>
<a {{ if key == active }}class="active"{{endif}} href="{{ paths.root }}path/{{key}}">{{category}}</a>
</li>
{% endif%}
{% endfor %}
</ul>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment