Add front matter to all files in a directory
Rather than add the same front matter to every file in a directory, Eleventy will automatically apply any values in a JSON file with the same name to every file.
Prerequisites
Directions
- Create a folder called posts in the root of your project
- Create a file called posts.json in the posts folder and add the following:
{
"layout": "base"
}
- Create another file in posts called my-first-post.md. You only need to add front matter for the title.
---
title: My First Post
---
- Create a second post, my-second-post.md. Again, you only need to add a title.
---
title: My Second Post
---
- You can now visit either of these pages, http://localhost:8080/posts/my-first-post/ and you'll see the page is using our base layout without having needed to specify it in each page's front matter.