13th Feb, 2022

Escpae liquid tags in jekyll code blocks

In my last post I learned that jekyll processes all liquid tags on a page, no matter if they are in a code block or somewhere else on the page.

So if I write something like

{% for index in (0..3) %} {{ index }} {% endfor %}

the actual output would be

0 1 2 3

as the liquid tags get executed.

To stop this behaviour, the jekyll documentation offers two solutions:

  1. Wrap the code block in {% raw %} and {% endraw %} tags. The example above would become
{% raw %} ```html {% for index in (0..3) %} {{ index }} {% endfor %} ``` {%
endraw %}
  1. Add render_with_liquid: false to the posts front matter, to disable it for the whole document
© 2024 Chris Jarling