Data Cascade
Highest to lowest-priority data cascade
- 7. Computed data: Highest precedence. Inject data properties into your data object that are based on other data values with the eleventyComputed feature.
Where is the datas: at any step of the cascade, declare an eleventyComputed data object.
Example: module.exports = { eleventyComputed: { dataCascade: { id: 'computed data, highest priority.', } } }; - 6. Template frontmatter: locally assigned front matter values override things further up the layout chain.
Where is the datas: datas inside the frontmatter of the template file.
Example: dataCascade: id: 'template frontmatter, 6th in the cascade.' - 5. Template data files: specific files of Json or JavaScript data that are paired by name with specific pages.
Where is the datas: JSON & JavaScript files in the same directory & the same name as the template.
Example: {'dataCascade': {'id': 'template data files, 5th in the cascade.'}} - 4. Directory data files: shared between multiple pages in a specific directory in your project.
Where is the datas: JSON & JavaScript files in the directory of the template with the same name as the directory.
Example: { 'dataCascade': { 'id': 'directory data files, 4th in the cascade.'}} - 3. Layout frontmatter: helpful for creating template inheritance features to show different data on each section based on the layout.
Where is the datas: frontmatter of layout files in the _layouts directory.
Example: dataCascade: id: 'layout frontmatter, 3rd in the cascade.' - 2. Config global data: use the configuration API to add global data to your templates.
Where is the datas: JavaScript argument in the eleventy.config.js file.
Example: eleventyConfig.addGlobalData('dataCascade.id', 'config global data, 2nd in the cascade.'); - 1. Global data: Weakest precedence. JavaScript or Json files stored by default in the src directory of your project.
Where is the datas: JSON & JavaScript files in the _data directory.
Example: {'id': 'global data, first in the cascade'}
Cascade example: computed data, highest priority.
A good blog about Eleventy data cascade