Applying frontmatter defaults to a whole folder of posts in eleventy

Using JSON data files to apply defaults

Jul 22, 2021 • • 🍿 1 min. read in eleventy

Why do this?

Eleventy uses YAML front matter at the top of your mardown files to specify variables and templates to use.


layout: layouts/tutorial.html
title: My first tutorial

However if you have a whole folder of markdown posts, specifying things that are the same across all posts (like the layout) is uneccessarily repetitive, and painful if you want to change things later.


Skip the common variables (like layout) and add them into a JSON file in the root of your directory of posts.


"layout": "layouts/tutorial.html"

Make sure it's named the same as your directory.

Then you can skip having to specify layout in your markdown files:

title: My first tutorial

...which simplifies things you have lots of posts, and means you have a single place to make any future changes. Find out more about Template and Directory specific data files in the 11ty docs.

Posted in eleventy