Menu
- Why Eleventy?
- Get Started
- Community
- Working with Templates
- Using Data
- Configuration
- Template Languages
- Plugins
- API Services
- Release History
- Advanced
5.81s
40.14s
Global Data Files
Global data is data that is exposed to every template in an Eleventy project.
One way to create global data is through global data files: JSON and JavaScript files placed inside of the global data folder. The global data folder is placed inside the project's input directory (set by the dir.input
configuration option), and the name of the global data folder is set by the dir.data
configuration option (_data
by default). All *.json
and module.exports
values from *.js
files in this directory will be added into a global data object available to all templates.
You may also be interested in config global dataAdded in v1.0.0, which is another way to add global data to every template in an Eleventy project.
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):
- Computed Data
- Front Matter Data in a Template
- Template Data Files
- Directory Data Files (and ascending Parent Directories)
- Front Matter Data in Layouts (this moved in 1.0)
- Configuration API Global Data
- Global Data Files ⬅
From the Community Jump to heading
×26 resources courtesy of 11tybundle.dev curated by Bob Monsour
Expand to see 21 more resources.
Other pages in Data Cascade:
- Front Matter Data
- Template & Directory Data Files
- Global Data Files
- Data Deep Merge
- Config Global Data
- Computed Data