Front Matter Data #
Add data in your template front matter, like this:
---
title: My page title
---
<!doctype html>
<html>
…
The above is using YAML syntax. You can use other formats too.
Locally assigned front matter values override things further up the layout chain. Note also that layouts can contain front matter variables that you can use in your local template. Leaf template front matter takes precedence over layout front matter. Read more about Layouts.
Front Matter Configuration #
Here are a few special front matter keys you can assign:
permalink
: Add in front matter to change the output target of the current template. Normally, you cannot use template syntax for variables in front matter, butpermalink
is an exception. Read more about Permalinks.dynamicPermalink
: Enable or disable template syntax for thepermalink
key. Read more.layout
: Wrap current template with a layout template found in the_includes
folder. Read more about Layouts.pagination
: Enable to iterate over data. Output multiple HTML files from a single template. Read more about Pagination.tags
: A single string or array that identifies that a piece of content is part of a collection. Collections can be reused in any other template. Read more about Collections.date
: Override the default date (file creation) to customize how the file is sorted in a collection. Read more at Content Dates.templateEngineOverride
: Override the template engine on a per-file basis, usually configured with a file extension or globally using themarkdownTemplateEngine
andhtmlTemplateEngine
configuration options. Read more about Changing a Template’s Rendering Engine.eleventyExcludeFromCollections
: New in v0.8.0 Set totrue
to exclude this content from any and all Collections (those tagged in data or setup using the Configuration API).
Sources of Data #
When the data is merged in the Eleventy Data Cascade, the order of priority for sources of data is (from highest priority to lowest):
- Front Matter Data in a Template ⬅
- Front Matter Data in Layouts
- Template Data Files
- Directory Data Files (and ascending Parent Directories)
- Global Data Files
Alternative Front Matter Formats #
Eleventy uses the gray-matter
package for front matter processing. gray-matter
includes support for YAML, JSON, and even arbitrary JavaScript front matter.
JSON Front Matter #
---json
{
"title": "My page title"
}
---
<!doctype html>
<html>
…
JavaScript Front Matter #
Note that Liquid templates do not allow executing a function in output {{ currentDate() }}
. However, the following example does work in Nunjucks:
---js
{
title: "My page title",
currentDate: function() {
// You can have a JavaScript function here!
return (new Date()).toLocaleString();
}
}
---
<!doctype html>
<html>
<!-- … -->
<body>
<h1>{{ title }}</h1>
<p>Published on {{ currentDate() }}</p>
<!-- … -->
Add your own format New in v0.9.0 #
You can customize Front Matter Parsing in Eleventy to add your own custom format. We have an example to do this with support for TOML.
Advanced: Customize Front Matter Parsing New in v0.9.0 #
Configure front matter for customized excerpts, TOML parsing, and more.