Add a layout
Adding a layout allows you to insert the content of multiple HTML or Markdown pages into a common template.
Directions
- Create a folder in the root of your project called _includes
- Create a file inside of _includes called base.njk
- In base.njk add a basic HTML boilerplate and inside of the body add
{{ content | safe }}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Eleventy Project</title>
</head>
<body>
{{ content | safe }}
</body>
</html>
- In index.md add some front matter to the top of the page.
---
layout: base
---
-
Visit your index page and now it should be rendering as HTML instead of Markdown. https://localhost:8080/
-
Let's make our title dynamic. In _includes/base.njk, Replace the content of the title with
{{ title }}
<title>{{ title }}</title>
- Before
{{ content | safe }}
, add:
<h1>{{ title }}</h1>
- In index.md, add another line to your front matter:
title: My Eleventy Project
- Delete your title:
# My Eleventy Project