Night Owl logoNight Owl

Global data

Templates are provided with data when they render. To use the same global data across all of the templates in your project, point to an entry file in your Night Owl configuration.

export default {
  // The location of your global data file
  data: "src/_data/index.js",
}

Anything that is set in your global data is then available to every template when it renders. For example, you could provide a creation date in your global data to use on the footer of every page.

export default {
  created: new Date()
}

Merging data

Data can be set by pages, templates, layouts and in the global data file. Night Owl uses deep merging when combining the different levels of data.

If the same properties are defined at different levels, the page data has the highest precedence, followed by the template, the layout and finally the global data file.

Special properties

Some data changes the way Night Owl handles your template. For this reason, it’s best to avoid using them in your global data to avoid unexpected results. Read more about a template’s special properties.

The only exception to this rule is the layout property, which can be used to set a default layout for every template that generates a HTML page.

Page data

This page was rendered with the following data.

{
  "layout": "_/layouts/docs",
  "menu": {...},
  "filters": {...},
  "helpers": {...},
  "version": "0.5.4",
  "github": "https://github.com/stephenhutchings/night-owl/",
  "npm": "https://www.npmjs.com/package/night-owl",
  "hash": "lmu1z5z4",
  "thumbnail": "https://night-owl.s-ings.com/assets/thumb.png",
  "isDev": false,
  "tags": [ "configuration" ],
  "title": "Global data",
  "description": "Provide the same data to every template",
  "url": "/docs/configuration/global-data/",
  "meta": {
    "url": "/docs/configuration/global-data/",
    "src": "src/docs/03-configuration/03-global-data.md",
    "dist": "dist/docs/configuration/global-data/index.html",
    "collections": {
      "all": [...],
      "intro": [...],
      "commands": [...],
      "configuration": [...],
      "advanced": [...],
      "templates": [...]
    }
  },
  "content": "<p>Templates are provided with data when they render. To use the same global dat..."
}