An image of ram in a can Quick 11ty tip

The 11ty default filter (Nunjucks)

Originally Published: Feb 20, 2025 | Updated: Feb 20, 2025

So just an FYI so that this might help anyone else out. This is an example of how to use the 11ty Nunjucks "default" filter. It took me forever to figure out how to actually do this. I had to look for an example and I finally figured out what each thing was called to be able to search for it.

So, what is the default filter? This is a filter that you can use to apply what you want a variable to be if it isn't given in the markdown document. So for instance, if I want my website title to be "Skewb's Blog" when one isn't supplied by the new webpage, I can do this by putting <title>{{ title or "Skewb's Blog" }} </title> in my base.html file.

This means that if the page that I am working on doesn't define the "title" fontmatter tag then "Skewb's Blog" will be used.

I found an example of the old and new behavior. Both work at the time of writing.