104

This sounds very easy, however I couldn't find it anywhere in the docs. How can I write {% this %} in a liquid template, without it being processed by the engine?

1

9 Answers 9

138

it is possible to disable liquid processing engine using the raw tag:

{% raw  %}
{% this %}
{% endraw %}

will display

{% this %}
6
127

For future searchers, there is a way to escape without plugins, use the code below:

{{ "{% this " }}%}

and for tags, to escape {{ this }} use:

{{ "{{ this " }}}}

There is also a jekyll plugin for this which makes it a whole lot easier: https://gist.github.com/1020852

Raw tag for jekyll. Keeps liquid from parsing text betweeen {% raw %} and {% endraw %}

Reference

5
  • 1
    Great, thanks for the reference. For some reason I wasn't able tno find this in the liquid docs.
    – Attila O.
    May 4, 2011 at 11:57
  • 10
    You no longer need a plugin to use {% raw %}, for me it works out of the box and now it's in the docs
    – fregante
    Feb 27, 2014 at 15:33
  • 2
    is it possible to escape code with ``` instead of {% in jekyll?
    – Jas
    Dec 17, 2014 at 8:42
  • 3
    The first couple suggestions didn't work for me, but using raw did: {% raw %}{{ this }}{% endraw %}. Jan 6, 2015 at 18:29
  • it worked, thanks ... see a real example here g14n.info/2014/08/moving-from-blogger-to-github-pages/#comments Apr 29, 2015 at 22:10
15

BTW:

If you want to display {{ "{% this " }}%}in Jekyll, you can code like this:

{{ "{{ " }}"{{ "{% this" }} " }}{{ "}}%}

To escape {{ "{{ this " }}}}use:

{{ "{{ " }}"{{ "{{ this" }} " }}{{ "}}}}
1
  • 31
    Ha, ha hahahah ah aaaaahhh.
    – RobW
    Jul 16, 2013 at 2:01
15

You can escape liquid tags in Jekyll posts using {% raw %} {% endraw %} i.e

{% raw %}
  {% for post in site.posts %}
     {{ post.content }}
  {% endfor %}

{% endraw %}

will produce

  {% for post in site.posts %}
     {{ post.content }}
  {% endfor %}
10

There is another option: to use HTML special characters codes for replacing the curly braces with its matching codes:

  • replace each { with {
  • replace each } with }

For more details about this solution see: http://www.tikalk.com/devops/curly_brances_workaround/

4

I found a omnipotent way to display any text with curly braces. You can assign plain text to a variable, and display it.

{% assign var = "{{ sth }}" %}
{{ var }}
1
  • Thank you! Useful to escape double or single quotes
    – JumpLink
    Jan 6, 2017 at 17:27
2

As mentioned here also, plain {% raw %} and {% endraw %} are only the second best solution since those are shown if you look up the Markdown on normal github.com.

The best way is to put {% raw %} and {% endraw %} in HTML comments:

<!-- {% raw %} -->
something with curlky brackets like { this } and { that }
<!-- {% endraw %} -->

Due to the HTML comments it is seen by Github as a comment. In Github pages the raw tags will prevent the parsing of the curly brackets in between the tags.

1
  • I like this method as, for some reason, it doesn't mess with my excerpts. Aug 14, 2020 at 15:15
1

I tried {% raw %} something {% endraw %} ,

and {{ "{% this " }}%}. But they both don't work.

finally, my working answer is {{ "{%" xxx }} something }}.

My code:

{{ "{%" }} extends 'xadmin/base_site.html' %}
{{ "{%" }} block nav_form %}
    <h3>{{ "{{" }} title }}</h3>
    {{ "{%" }} for i in context1 %}
        <p>{{ "{{" }} i }}</p>
    {{ "{%" }} endfor %}
{{ "{%" }} endblock %}

The result:

{% extends 'xadmin/base_site.html' %}
{% block nav_form %}
    <h3>{{ title }}</h3>
    {% for i in context1 %}
        <p>{{ i }}</p>
    {% endfor %}
{% endblock %}

0

Allows output of Liquid code on a page without being parsed.

{% raw %}{{ 5 | plus: 6 }}{% endraw %} equals 11.

{{ 5 | plus: 6 }} equals 11.

For more details about this solution see: https://www.shoplazza.dev/docs/theme-tags

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.