Skip to content

Instantly share code, notes, and snippets.

@peruvianidol
Last active July 21, 2021 02:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peruvianidol/fbe55fd30a89deb8911a8831cedd3198 to your computer and use it in GitHub Desktop.
Save peruvianidol/fbe55fd30a89deb8911a8831cedd3198 to your computer and use it in GitHub Desktop.
Filters in Custom Shortcodes in Eleventy
// from https://www.11ty.dev/docs/filters/#access-existing-filters
// in .eleventy.js
eleventyConfig.addPairedShortcode("anchor", function(heading) {
return `
<h2><a id="${eleventyConfig.getFilter('slug')(heading)}" href="#${eleventyConfig.getFilter('slug')(heading)}">
${heading}
</a></h2>`
});
// in any HTML or Nunjucks file
{% anchor %}Filters in Custom Shortcodes{% endanchor %}
// Compiled HTML
<h2><a id="filters-in-custom-shortcodes" href="#filters-in-custom-shortcodes">Filters in Custom Shortcodes</a></h2>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment