Spelt Docs

Categories

When creating your blog, you might want to organize your blog posts by assigning each of them to a category. To assign a post to a category you set the category variable in the front matter.

---
layout: post
title: The 10 best pets for a mission to Mars
category: space
---

A post can also belong to multiple categories. This can be specified by setting the categories (plural) variable to a YAML list or a comma-separated string, e.g.:

---
layout: post
title: The 10 best pets for a mission to Mars
categories: space, important-questions
---

Rendering

Defining a category will expose the name of that category as a variable to your template files. This variable contains a list of all blog posts assigned to that category. To render the titles of all blog posts in the templates category, you could write the following:

{% for post in site.categories.space %}
  <h2><a href="{{ post.url }}">{{ post.title }}</a></h2>
{% endfor %}