Skip to content
This repository was archived by the owner on Aug 26, 2025. It is now read-only.

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

10 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

demo-eleventy-javascript-front-matter

✅ This functionality is now available in Eleventy v3 core and doesn’t require any additional configuration — just use the js or javascript front matter type! This repo is specifically for Eleventy v2.

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

Sponsor this project

  •