Code Snippets Nunjucks

Short texts Nunjucks 🧑‍💻 Code snippets Nunjucks ✍️ Reading lists Nunjucks 👀

Create SVG sprites in Eleventy using a directory SVG files as a reference

module.exports = (eleventyConfig) => { // … // Icon Sprite eleventyConfig.addWatchTarget(“src/assets/svgs/”); eleventyConfig.on(“beforeBuild”, svgsprite); eleventyConfig.addNunjucksAsyncShortcode(“svgsprite”, svgsprite); eleventyConfig.addShortcode(“icon”, (name) => { return “; }); // … }; const fs = require(“fs-extra”); const path = require(“path”); const util = require(“util”); const glob = require(“glob”); const File = require(“vinyl”); const svgSprite = require(“svg-sprite”); let spriteContent = null; // Placeholder […]

lib.njk

{% extends ‘base.njk’ %} {% block scripts %} {% endblock %}

madlib.njk

— layout: ‘lib.njk’ pagination: data: madlibs alias: madlib size: 1 permalink: “madlibs/{{ madlib.slug | slug }}/index.html” — // page content

full lib.njk

{% extends ‘base.njk’ %} {% block scripts %} {% endblock %}

test

{% include “_header-page.njk” %}