This post is in Draft Mode - it will not appear on the site or in search results

How to escape nunjucks in markdown files in Eleventy

-

This issue occurs when you want to write a post or wiki that illustrates how to use nunjucks syntax

Let's say you intend to write this:

Output a date with {{'1/1/2010' | dateDisplay}}

But what gets rendered is this

Output a date with January 1st 2010

That's because when markdown files are processed through eleventy, we can extend the available markdown syntax with templating options as well. In our case, we're using nunjucks by setting it in the configuration file:

module.exports = {
    markdownTemplateEngine: "njk"
};

Here are the criteria we'll try to optimize for:

Nunjucks has three types of tags:

Overriding the template language