I Finally Understand Eleventy’s Data Cascade. The article explains the author's understanding of Eleventy's data cascade, which is the system that aggregates data from multiple sources and determines precedence when conflicts arise. The cascade prioritizes data based on colocation, meaning data defined closer to a specific template (like frontmatter) overrides more global data. Global data, defined in the `_data/` folder or config file, is evaluated first and has the weakest precedence, making it suitable for site-wide values. This is a living document What follows is my mental model of how Eleventy aggregates data for templates. It’s subject to change as I learn more and more about Eleventy, and as Eleventy itself changes. This post walks through the data cascade as of the 2.0 release. You can skip to the changes that came with 1.0 changes-to-the-data-cascade-in-eleventy-10 , or the pre-1.0 version of this article /blog/eleventy-data-cascade/original/ has been archived if you need that instead Introduction Last summer, I overhauled my blog /blog/in-with-the-new/ , rebuilding it from the ground up with a static site generator called Eleventy https://www.11ty.dev/ . I had just come off the heels of taking Andy Bell’s Learn Eleventy From Scratch https://learneleventyfromscratch.com/ course, and I was feeling jazzed about being able to build lightweight sites. There was just one thing, one piece of Eleventy, that took me months to fully wrap my head around: the data cascade. Eleventy is powered by templating. You can inject data into your contents and layouts using various templating languages https://www.11ty.dev/docs/languages/ . For instance, say your blogpost has some title data. You could use that title in your layouts When Eleventy generates the pages of your site, it aggregates data supplied from several places and then injects that data into your contents. The process of aggregating this data from each of these different places and deciding which data should have precedence in the case of a conflict is what Eleventy calls the data cascade https://www.11ty.dev/docs/data-cascade/ . For several months, I didn’t feel like I had a good grip on the cascade. I had numerous questions: How would I know whether data was available to me at any given moment? Where could I use data? Which data would override which other data? Why should I place some data here, and some other data there? I had to read Eleventy’s docs about data several times, and then put it into practice on several different sites in several different ways. I’m especially grateful for the Lunch.dev Community Calendar project https://github.com/LunchDevCommunity/community-calendar , which has been built out over several live group sessions. You can practically see the moment the cascade clicked for me in our session on “Add to Calendar” links with computed data https://events.lunch.dev/add-calendar-links-to-11ty-with-computed-data/ . What follows is my mental model of Eleventy’s data cascade, presented in the hopes that it will help you wrap your head around where you can place data in your Eleventy sites and why. A Few Definitions - Templates are the files that define your contents. In a blog, for instance, this could be the Markdown file that contains your blogpost. - Layouts are templates that wrap around other templates. You could, for instance, wrap your blogpost’s template in a layout that provides the page’s HTML scaffold and its styles. - Data is provided to your templates and, therefore, to your layouts as well as variables that can be injected into your contents. Each template is supplied its own data, based on the data cascade. Colocation While I was ambling along with the data cascade, able to define and use data but not totally sure why and how it worked, I built up a bit of an intuition about how it worked: colocation . Data that is defined closer to your content will be evaluated later in the data cascade, and will have a higher precedence. I’m happy to report that this holds up Even if you don’t totally understand how the data cascade works, you can debug your data first by looking at a template’s frontmatter, and then working your way out. Step 1: Global Data The first data to be evaluated is global data. Global data https://www.11ty.dev/docs/data-global/ is available in every template and layout, but it has the weakest precedence—it’ll be overruled by any more-specific data that gets evaluated later. This makes it really ideal for site-wide concerns , as well as for data that needs to be fetched from external sources such as APIs. Eleventy provides two ways to supply global data: global data files and through your Eleventy config file step-2-config-global-data . In this first step of the data cascade, Eleventy looks at global data defined through global data files. By default, Eleventy will look for a folder at the root level of your project called data/ . This is your global data folder. You can configure your global data folder’s path https://www.11ty.dev/docs/config/ directory-for-global-data-files in your Eleventy configuration file if you want, but I tend not to. The default works just fine for me. Eleventy will look for all .js and .json files in your global data folder, and expose their exports to your templates, using the global data file’s name as the variable name. For instance, this site has a data/ global data file that looks like this: navigationLinks .json Eleventy takes that JSON array and exposes it for me as the variable in every one of my templates and layouts. In one of my layouts, I iterate over that navigationLinks navigationLinks variable to populate the page’s