Tags
Use tags to group and organize pages
You can assign one or multiple tags to pages using the tags
variable. Tags allows you to group content in interesting ways.
For example, in a blog site, you may want to group posts of different categories:
---
title: The history of the static site generators
tags:
- post
- ssg
---
This post has two tags, one used to identify the type of page (post) and another with the topic (ssg). To collect all pages tagged as post
in the layouts, use the search
object:
<ul>
{% for post in search.pages("post") %}
<li>{{ post.data.title }}</li>
{% endfor %}
</ul>
And to get all pages tagged as post
and ssg
add the two tags names separated with a space:
<ul>
{% for post in search.pages("post ssg") %}
<li>{{ post.data.title }}</li>
{% endfor %}
</ul>
Tags in _data
Unlike other values, when you define tags
in a _data.*
file and in the pages, the value is not overridden, but aggregated. In other words: the page will have all tags defined in _data.*
and in the page. In the previous example, instead of assigning the "post" tag to all pages manually, you could define it in a _data.*
file in the directory where all posts are stored and use the front matter to assign the other tags individually.