What's on this page
Organize pages with tags and categories
Taxonomies let you classify pages with terms (e.g. PHP) grouped in vocabularies (e.g. tags). Cecil then generates a page per vocabulary and a page per term.
Declare vocabularies
Vocabularies are declared in cecil.yml, paired by plural and singular names:
taxonomies:
categories: category
tags: tag
Classify pages
Add terms in the front matter of your pages, using the plural name of the vocabulary:
---
title: My first post
categories: ["Development"]
tags: ["PHP", "Static site"]
---
Cecil generates:
/tags/: the list of the terms of the vocabulary/tags/php/and/tags/static-site/: the list of the pages of each term
Customize the list of terms
The vocabulary template is named after the plural, e.g. layouts/taxonomy/tags.html.twig:
{% extends 'page.html.twig' %}
{% block content %}
<h1>{{ page.title }}</h1>
<ul>
{% for term in page.terms %}
<li><a href="{{ url(term.id) }}">{{ term.name }}</a> ({{ term|length }})</li>
{% endfor %}
</ul>
{% endblock %}
Customize the pages of a term
The term template is named after the singular, e.g. layouts/taxonomy/tag.html.twig:
{% extends 'page.html.twig' %}
{% block content %}
<h1>{{ page.title }}</h1>
{% for p in page.paginator.pages ?? page.pages %}
<article>
<h2><a href="{{ url(p) }}">{{ p.title }}</a></h2>
</article>
{% endfor %}
<a href="{{ url(page.plural) }}">All {{ page.plural }}</a>
{% endblock %}
Display the terms of a page
In a page template, link each term to its page:
{% for tag in page.tags ?? [] %}
<a href="{{ url('tags/' ~ tag) }}">{{ tag }}</a>
{% endfor %}
Or use the built-in partial: {{ include('partials/terms-list.html.twig', {vocabulary: 'tags'}) }}.