Skip to main content

Use the {% raw %} tag to describe Liquid in Liquid

If you’re trying to write about using Liquid tags in a Liquid-based site, wrapping your tags in the {% raw %} tag will prevent them being rendered.

This is a problem I had when trying to write my TIL about the {% capture %} tag. I’d written an example in my Markdown source code:

You can use the [capture tag] to create a new variable:

```liquid
{% capture variable %}
  value
{% endcapture %}
```

but the rendered <pre> block was empty – Liquid ran before the Markdown processor, so it had captured the variable and left empty space.

I found an answer by Marcel Jackwerth on Stack Overflow that suggests using the {% raw %} tag, which in this case became:

You can use the [capture tag] to create a new variable:

```liquid
{% raw %}{% capture variable %}
  value
{% endcapture %}{% endraw %}
```

(Trying to write a TIL about the {% raw %} is even more of a mess of raw tags and percent-encoding to get the right output from Liquid.)