Skip to navigation Skip to main content

Data Cascade

On this page

In Eleventy, data is merged from multiple different sources before the template is rendered. The data is merged in what Eleventy calls the Data Cascade.

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):

  1. Computed Data
  2. Front Matter Data in a Template
  3. Template Data Files
  4. Directory Data Files (and ascending Parent Directories)
  5. Front Matter Data in Layouts (this moved in 1.0)
  6. Configuration API Global Data
  7. Global Data Files

Example

Filename my-template.md
---
title: This is a Good Blog Post
tags:
  - CSS
  - HTML
layout: my-layout.njk
---
Filename _includes/my-layout.njk
---
title: This is a Very Good Blog Post
author: Zach
tags:
  - JavaScript
---

Note that when my-template.md and my-layout.njk share data with the same object key (title and tags), the “leaf template” my-template.md takes precedence.

The data cascade results in the following data when my-template.md is rendered:

Syntax JavaScript
{
	"title": "This is a Good Blog Post",
	"author": "Zach",
	"tags": ["CSS", "HTML", "JavaScript"],
	"layout": "my-layout.njk"
}

Eleventy does a deep merge to combine Object literals and Arrays. (Wait, where did the option to opt-out of deep-merging go?) You can override this on a per-property basis with the override: prefix.

Using the override: prefix

Use the override: prefix on any data key to opt-out of deep-merge behavior for specific values or nested values.

Filename posts/posts.json
{
	"tags": ["posts"]
}
Filename posts/firstpost.md
---
# Instead of merging the array, this creates an empty set
override:tags: []
---

Even though normally the posts/firstpost.md file would inherit the posts tag from the directory data file (per normal data cascade rules), we can override the tags value to be an empty array to opt-out of Array merge behavior.

From the Community

×49 resources via 11tybundle.dev curated by Favicon for v1.indieweb-avatar.11ty.dev/https%3A%2F%2Fwww.bobmonsour.com%2FBob Monsour.

Expand to see 44 more resources.

Other pages in Using Data