Skip to content

Testing global site information in the _data directory.

Notifications You must be signed in to change notification settings

pdehaan/11ty-global-data

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

11ty-global-data

Testing global site information in the _data directory.

This repo shows how you can get data from a global data file in your project's _data/ directory and use it in your templates.

tree
.
├── package-lock.json
├── package.json
│
├── site/ # INPUT DIR
│   ├── _data/
│   │   └── site.json
│   └── pages/
│       └── index.njk
│
└── www/ # OUTPUT DIR
    └── index.html

4 directories, 5 files

If you wanted to use dynamic data in your global site data file, you could rename the site/_data/site.json file to site/_data/site.js and use JavaScript and

// ./site/_data/site.js
module.exports = {
  author: "Peter deHaan",
  github: "pdehaan",
  twitter: "pdehaan",
  license: "MPL-2.0"
};

Or even return an async function, if you wanted to do any async data fetching/processing:

// ./site/_data/site.js
module.exports = async () => {
  return {
    author: "Peter deHaan",
    github: "pdehaan",
    twitter: "pdehaan",
    license: "MPL-2.0"
  };
};

About

Testing global site information in the _data directory.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published