11ty

Eleventy Documentation

This documentation is for an older version. Go to the newest Eleventy docs or check out the full release history.

Documentation Pages

Template and Directory Specific Data Files #

While you can provide global data files to supply data to all of your templates, you may want some of your data to be available locally only to one specific template or to a directory of templates. For that use, we also search for JSON and JavaScript data files in specific places in your directory structure.

Important exception: Template and Directory Specific Data Files are not preprocessed through a templating engine. Global Data files are.

For example, consider a template located at posts/subdir/my-first-blog-post.md. Eleventy will look for data in the following places (starting with highest priority, local data keys override global data):

  1. Template Front Matter Data
  2. Template Data File (data is only applied to posts/subdir/my-first-blog-post.md)
    • posts/subdir/my-first-blog-post.11tydata.js New in v0.5.3
    • posts/subdir/my-first-blog-post.11tydata.json New in v0.5.3
    • posts/subdir/my-first-blog-post.json
  3. Directory Data File (data applies to all templates in posts/subdir/*)
    • posts/subdir/subdir.11tydata.js New in v0.5.3
    • posts/subdir/subdir.11tydata.json New in v0.5.3
    • posts/subdir/subdir.json
  4. Parent Directory Data File (data applies to all templates in posts/**/*, including subdirectories)
    • posts/posts.11tydata.js New in v0.5.3
    • posts/posts.11tydata.json New in v0.5.3
    • posts/posts.json
  5. Global Data Files in _data/* (available to all templates)

(Changed in Eleventy v0.2.15 to search parent directories for data files—specifically step 4 above was added in the sequence)

Change the .11tydata.js file suffix #

New in v0.5.3 Use the Configuration API to change the file suffix used to search for Eleventy data files.

Example: Apply a default layout to multiple templates #

Try adding { "layout": "layouts/post.njk" } to posts/posts.json to configure a layout for all of the templates inside of posts/*.

Sources of Data #

The order of priority for sources of data is (from highest priority to lowest):

  1. Front Matter Data
  2. Template Data Files
  3. Directory Data Files (and ascending Parent Directories)
  4. Global Data Files