Stand with Ukraine 🇺🇦
Eleventy
The possum is Eleventy’s mascot

Eleventy Documentation

Menu

Global Data Files Jump to heading

Your global data folder is controlled by the dir.data configuration option. All *.json and module.exports values from *.js files in this directory will be added into a global data object available to all templates.

Example Jump to heading

Consider a JSON data file located at _data/userList.json with the following content:

[
"user1",
"user2"
]

This data will be available to your templates under the userList key like this:

{
userList: [
"user1",
"user2"
]
}

Folders Jump to heading

If a data file is in a folder, the folder name will inform your global data object structure. For example, in our previous example, consider if our userList.json file was moved into a users folder at _data/users/userList.json.

Our data will be now available to your templates under a users key like so:

{
users: {
userList: [
"user1",
"user2"
]
}
}

Using JavaScript instead of JSON Jump to heading

Read more about using module.exports values in arbitrary JavaScript data files.

Sources of Data Jump to heading

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. Front Matter Data in Layouts (only in 0.x)
  4. Template Data Files
  5. Directory Data Files (and ascending Parent Directories)
  6. Front Matter Data in Layouts (moved in 1.0)
  7. Configuration API Global Data
  8. Global Data Files

Other pages in Data Cascade:


Related Docs