Skip to content

11ty Filters for Tags

Posted on: Nov 24, 2020 by Stephanie Eckles
🍿 1 min. read

Filters for working with tags

hasTag Filter

Useful when using a layout for multiple collection types, such as to provide a different call to action or link.

Usage within a layout for a single page:

{% if tags | hasTag('post') %}

eleventyConfig.addFilter("hasTag", (tags, tag) => {
return (tags || []).includes(tag);
});

Could be genericized to hasItem and used on any array data type.

View more config samples