This will look for a mylayout.njk Nunjucks template file in your includes folder (_includes/mylayout.njk). You can use any template type in your layout—it doesn’t have to match the template type of the content. An ejs template can use a njk layout, for example.

If you omit the file extension (layout: mylayout), eleventy will cycle through all of the supported template formats (mylayout.*) to look for a matching layout file.

Next, we need to create a mylayout.njk file. It can contain any type of text, but here we’re using HTML:

Note that the layout template will populate the content data with the child template’s content. Also note that we don’t want to double-escape the output, so we’re using the provided Nunjuck’s safe filter here (see more language double-escaping syntax below).

Layouts can contain their own front matter data! It’ll be merged with the content’s data on render (content data takes precedence, if conflicting keys arise).

Take note that in Eleventy’s Data Cascade, front matter data in your template is merged with Layout front matter data! All data is merged ahead of time so that you can mix and match variables in your content and layout templates interchangeably.

Note that front matter data set in a content template takes priority over layout front matter! Chained layouts (described below) have similar merge behavior. The closer to the content, the higher priority the data.

Configuration API: use eleventyConfig.addLayoutAlias(from, to) to add layout aliases! Say you have a bunch of existing content using layout: post. If you don’t want to rewrite all of those values, just map post to a new file like this:

Your layouts can also use a layout! Add the same layout front matter data to your layout template file and it’ll chain. You do not have to use the same template engine across layouts and content! You can mix and match.

It is worth noting that existing template reuse mechanisms built into different templating languages are still available to you. For instance, Nunjucks calls it Template Inheritance and exposes with {% extends %}. Eleventy’s layout system exists a layer above this and exposes a nice multi-template-language mechanism to configure layouts in your content’s front matter and share data between them.

“I looked into and actively tried using various static site generators for this project. Eleventy was the only one I could find that gave me the fine-grained control I needed at blazingly fast build times.”—Mathias Bynens