├── .gitignore ├── src ├── _data │ ├── site.js │ └── bar.js ├── liquid.liquid ├── nunjucks.njk └── eleventy.11ty.js ├── www ├── liquid │ └── index.html ├── nunjucks │ └── index.html └── eleventy │ └── index.html ├── package.json └── .eleventy.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /src/_data/site.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | baseUrl: "https://11ty.dev/", 3 | author: "John Smith", 4 | }; 5 | -------------------------------------------------------------------------------- /src/_data/bar.js: -------------------------------------------------------------------------------- 1 | module.exports = [ 2 | "one", 3 | "two", 4 | "three", 5 | "four", 6 | "five", 7 | ]; 8 | -------------------------------------------------------------------------------- /src/liquid.liquid: -------------------------------------------------------------------------------- 1 | --- 2 | title: LiquidJS 3 | --- 4 | 5 |

{{ title }}

6 |
{{ bar | foo }}
7 |
{{ "first" | fooLiquid: "second" }}
8 | -------------------------------------------------------------------------------- /src/nunjucks.njk: -------------------------------------------------------------------------------- 1 | --- 2 | title: Nunjucks 3 | --- 4 | 5 |

{{ title }}

6 |
{{ bar | foo | safe }}
7 |
{{ "first" | fooNjk("second") | safe }}
8 | -------------------------------------------------------------------------------- /www/liquid/index.html: -------------------------------------------------------------------------------- 1 |

LiquidJS

2 |
foo=["one","two","three","four","five"]
3 |
 4 |       site.author=John Smith;
 5 |       title=LiquidJS;
 6 |       arr="first";
 7 |       prop2=second;
 8 |     
10 | -------------------------------------------------------------------------------- /www/nunjucks/index.html: -------------------------------------------------------------------------------- 1 |

Nunjucks

2 |
foo=["one","two","three","four","five"]
3 |
 4 |       site.author=John Smith;
 5 |       title=Nunjucks;
 6 |       arr="first";
 7 |       prop2=second;
 8 |     
10 | -------------------------------------------------------------------------------- /www/eleventy/index.html: -------------------------------------------------------------------------------- 1 |

eleventy.11ty.js

2 |
foo=["one","two","three","four","five"]
3 |
 4 |       site.author=John Smith;
 5 |       title=eleventy.11ty.js;
 6 |       arr="first";
 7 |       prop2=second;
 8 |     
10 | -------------------------------------------------------------------------------- /src/eleventy.11ty.js: -------------------------------------------------------------------------------- 1 | module.exports = class Home { 2 | get data() { 3 | return { 4 | title: "eleventy.11ty.js", 5 | }; 6 | } 7 | async render(data) { 8 | // console.log(Object.keys(data).sort()); 9 | const { site, title } = data; 10 | return ` 11 |

${ data.title }

12 |
${ this.foo(data.bar) }
13 |
${ this.fooJs("first", "second", site, title)}
14 | `; 15 | } 16 | }; 17 | 18 | {/*

{{ title }}

19 |
{{ bar | foo | safe }}
20 |
{{ "first" | fooNjk("second") | safe }}
*/} 21 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "11ty-2841", 3 | "description": "", 4 | "version": "1.0.0", 5 | "author": "Peter deHaan ", 6 | "bugs": { 7 | "url": "https://github.com/pdehaan/11ty-2841/issues" 8 | }, 9 | "devDependencies": { 10 | "@11ty/eleventy": "^1.0.2" 11 | }, 12 | "homepage": "https://github.com/pdehaan/11ty-2841#readme", 13 | "keywords": [], 14 | "license": "MPL-2.0", 15 | "main": ".eleventy.js", 16 | "repository": { 17 | "type": "git", 18 | "url": "git+https://github.com/pdehaan/11ty-2841.git" 19 | }, 20 | "scripts": { 21 | "build": "eleventy", 22 | "postbuild": "npx prettier www --write", 23 | "test": "echo \"Error: no test specified\" && exit 1" 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.eleventy.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @param {import("@11ty/eleventy/src/UserConfig")} eleventyConfig 3 | * @returns {ReturnType} 4 | */ 5 | module.exports = function (eleventyConfig) { 6 | eleventyConfig.addFilter("foo", function (arr = []) { 7 | return `foo=${JSON.stringify(arr)}`; 8 | }); 9 | 10 | eleventyConfig.addNunjucksFilter("fooNjk", function (arr = [], prop2) { 11 | // Global data is available via `this.ctx` for Nunjucks. 12 | const { site, title } = this.ctx; 13 | return ` 14 | site.author=${site.author}; 15 | title=${title}; 16 | arr=${JSON.stringify(arr)}; 17 | prop2=${prop2}; 18 | `; 19 | }); 20 | 21 | eleventyConfig.addLiquidFilter("fooLiquid", function (arr = [], prop2) { 22 | // Global data is available via `this.context.environments` for LiquidJS. 23 | const { site, title } = this.context.environments; 24 | return ` 25 | site.author=${site.author}; 26 | title=${title}; 27 | arr=${JSON.stringify(arr)}; 28 | prop2=${prop2}; 29 | `; 30 | }); 31 | 32 | eleventyConfig.addJavaScriptFunction("fooJs", function (arr = [], prop2, site, title) { 33 | // Couldn't find global data when using JavaScript functions (via .11ty.js templates), 34 | // but they were available via data cascade, so I passed them from my .11ty.js file. 35 | return ` 36 | site.author=${site.author}; 37 | title=${title}; 38 | arr=${JSON.stringify(arr)}; 39 | prop2=${prop2}; 40 | `; 41 | }); 42 | 43 | return { 44 | dir: { 45 | input: "src", 46 | output: "www", 47 | } 48 | }; 49 | }; 50 | --------------------------------------------------------------------------------