Karly Nelson
👾

How to escape code in Markdown in Eleventy (11ty)

Published: September 19, 2024


Table of Contents

The Problem

In my "How to handle dates in 11ty" article I wanted to show some of my 11ty code in Markdown, but it tried to compile things like {{content}} and actually put content in there.

Solution Summary

Wrap your code in the raw tag. See Liquid Docs.

Explanation

Eleventy's default markdownTemplateEngine is Liquid, and Liquid has a tag you can use called raw that "outputs any Liquid code as text instead of rendering it."

Ironically you can't wrap a raw tag in another raw tag so the only way for me to show the full code was to use a Github Gist: