Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Grav template for automagic list of taxonomies
{% embed 'partials/base.html.twig' %}
{% block content %}
{% set taxname = uri.query|split('=')[0] %}
{% set taxval = uri.query|split('=')[1]|replace({'+':" "}) %}
{% if taxname %}
{% set c = breadcrumbs.get() %}
{% set crumbs = c |merge([{'menu':taxname|pluralize|humanize,'url':"/taxonomy?#{taxname}",'routable':true}]) %}
{% if taxval %}
{% set crumbs = crumbs |merge([{'menu':taxval|humanize,'url':'/taxonomy','routable':false}]) %}
{% endif%}
{% endif %}
{% if config.plugins.breadcrumbs.enabled %}
{% include 'partials/breadcrumbs.html.twig' with {'crumbs':crumbs} %}
{% endif %}
<div class="blog-content-item grid pure-g-r">
{{ page.content }}
</div>
<div class="content-wrapper blog-content-list grid pure-g">
<div id="listing" class="block pure-u-2-3 h-feed">
{% if taxname %}
{% if taxval %}
<section class="topiclist">
<!-- taxonomy.findTaxonomy({(taxname): taxval}) -->
{% set collection = taxonomy.findTaxonomy({(taxname): taxval}) %}
{% include 'partials/item-cards.html.twig' with {'collection': collection,'params':[{'name':taxname, 'val': taxval}]} %}
</section>
{% else %}
<section>
<ul class='item-topics topics'>
{% for cat in taxonomy.taxonomy[taxname]|keys|sort %}
<a class="item-topic topic" href="{{ base_url }}/taxonomy?{{taxname}}={{taxval}}{{ cat | url_encode }}"><li class="{{ taxname }}">{{ cat|humanize }}</li></a>
{% endfor %}
</ul>
</section>
{% endif %}
{% else %}
<section>
<ul class="item-topics topics">
{% for key in taxonomy.taxonomy|keys %}
{% if key not in ['archives_month','archives_year','category','categorie'] %}
<a class="item-topic topic" href="{{ page.url }}?{{key}}">
<li class="{{ key }}" >{{key|capitalize|pluralize}}</li>
</a>
{% endif %}
{% endfor%}
</ul>
</section>
{% endif %}
</div>
</div>
{% endblock %}
{% endembed %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment