Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include Jekyll/Liquid code without rendering it

Tags:

jekyll

liquid

Is it possible to {% include file.html %} without the tags inside it getting rendered?

  • I've tried {% include file.html | escape_once %} which gives an error

  • running it through {% raw %} {% include file.html %} {% endraw %} which gives {% include file.html %} (not surprisingly).

I'm looking for something along the lines of {% include file.html | no_render %}

The reason I can't put the raw tags inside file.html is that I'm trying to reuse it as a template (it's a bit of a hack).

This would also be good for pages that are trying to self describe. I.e. This useful thing works like this: {% include useful_snippet.html | no_render %}

like image 386
Ben Avatar asked Jun 07 '16 19:06

Ben


1 Answers

useful_snippet.html

{% raw %}
  {% comment %}Alot of liquid code{% endcomment %}
  {% assign toto = "Welcome to the hack !" %}
  {% assign string = "a,b,c,d" %}
  {% assign array = string | split:"," %}
  {% for item in array %}
    {{ item }}
  {% endfor %}
{% endraw %}

base display

<pre><code>{% include useful_snippet.html %}</code></pre>

display with jekyll highlight tag

{% highlight liquid %}{% include useful_snippet.html %}{% endhighlight %}

Edit: In Jekyll only process, Liquid is rendered once. So, no way to get one template doing both rendering Liquid and rendering raw Liquid code.

If you want to go that way, you'll have to use generator plugin or hooks.

like image 136
David Jacquel Avatar answered Oct 22 '22 01:10

David Jacquel