Skip to content

Demo of free-form JavaScript in front matter to populate the Data Cascade.

Notifications You must be signed in to change notification settings

11ty/demo-eleventy-js-front-matter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo-eleventy-javascript-front-matter

A demo showing how to use free-form JavaScript in front matter to populate the data cascade.

This makes use of Eleventy’s custom front matter format configuration API.

Uses the node-retrieve-globals package.

Check out page.njk for a Nunjucks example but this will work in any Eleventy template type (including Custom ones).

Example

---javascript
const myString = "Hi";

// export a function
function myFunction() {}
---
<!-- The template content goes here -->
<div>{{ myString }}</div>
<div>{{ myFunction() }}</div>

More Advanced Examples

---javascript
// async-friendly
const myAsyncString = await Promise.resolve("HELLO FROM THE OTHER SIDE");

// export via destructuring assignment
const { myKey } = { myKey: "myValue" };
const [ first, second ] = [ "first", "second" ];

// export via dynamic import
const { noop } = await import("@zachleat/noop");

// access Node.js globals like console.log
console.log({ noop });
---
<!-- The template content goes here -->

About

Demo of free-form JavaScript in front matter to populate the Data Cascade.

Resources

Stars

Watchers

Forks