Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use {{ }} with Markdown

I would like to write {{ ... }} inside a code block using Markdown.

For example:

{{ var }}  

I don't know why it disappears. However I can write it outside a block of code: \ {\ { var \ } \ }.

like image 739
José Manuel Avatar asked Feb 17 '26 23:02

José Manuel


2 Answers

Github flavored markdown supports that

You should be able to do exactly that. I think you must be using a bugged markdown implementation (or one with a 'templating mechanism' where {{ xxx }} is treated like variable interpolation), in normal markdown the following code block should work:

{{ var }}

As you can see, the StackOverflow markdown processor is doing the right thing, it is putting {{ var }} verbatim in the code block.

But Jekyll is another story

If you are using Jekyll to create your github pages, be aware that {{ }} is used for variable interpolation. Jekyll uses Liquid for this. Documentation:

  • https://github.com/Shopify/liquid/wiki/Liquid-for-Designers
  • https://jekyllrb.com/docs/templates/

Your answer is probably here (there are multiple options): How to escape liquid template tags?

like image 199
Marcel Valdez Orozco Avatar answered Feb 21 '26 13:02

Marcel Valdez Orozco


You could use something like this.

{% highlight liquid %}
  {% raw %}
    {{ Your code here }}
  {% endraw %}
{% endhighlight %}

This will output the following code:

<code class="language-liquid" data-lang="liquid">  
  <span class="p">{{</span>
  <span class="w"> </span>
  <span class="nv">Your code here</span>
  <span class="w"> </span>
  <span class="p">}}</span>
</code>
like image 44
Alan Avatar answered Feb 21 '26 15:02

Alan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!