包含 Jekyll/Liquid 代码而不渲染它

Ben*_*Ben 7 liquid jekyll

是否可以{% include file.html %}不渲染其中的标签?

  • 我试过{% include file.html | escape_once %}这给出了一个错误

  • 运行它 {% raw %} {% include file.html %} {% endraw %} 给出{% include file.html %}(不足为奇)。

我正在寻找类似的东西 {% include file.html | no_render %}

我不能把原始标签放在里面的原因file.html是我试图将它作为模板重用(这有点像黑客)。

这对于试图自我描述的页面也有好处。IEThis useful thing works like this: {% include useful_snippet.html | no_render %}

Dav*_*uel 4

有用的_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 %}
Run Code Online (Sandbox Code Playgroud)

底座显示

<pre><code>{% include useful_snippet.html %}</code></pre>
Run Code Online (Sandbox Code Playgroud)

使用 jekyll 高亮标签显示

{% highlight liquid %}{% include useful_snippet.html %}{% endhighlight %}
Run Code Online (Sandbox Code Playgroud)

编辑:在仅限 Jekyll 的进程中,Liquid 被渲染一次。因此,没有办法让一个模板同时渲染 Liquid 和渲染原始 Liquid 代码。

如果你想这样做,你必须使用生成器插件钩子