Skip to content

Latest commit

 

History

History
58 lines (44 loc) · 1.36 KB

data-global.md

File metadata and controls

58 lines (44 loc) · 1.36 KB
eleventyNavigation relatedLinks
parent key order
Data Cascade
Global Data Files
3
/docs/config/#default-template-engine-for-global-data-files
Default Template Engine for Global Data Files

Global Data Files

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

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

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

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

Sources of Data

{% include "datasources.md" %}