【问题标题】:Liquid variable inside jekyll include parameterjekyll 中的液体变量包含参数
【发布时间】:2020-05-15 03:20:56
【问题描述】:

我在_includes 中有一个 jekyll 部分,它在其内容周围包裹了一个彩色 div。部分 (callout.html) 看起来像这样:

<div markdown="1" class="callout">
    {{ include.content }}
</div>

我在test.md 中这样称呼它:

{% include callout.html content="Content to be filled with a URL: {{ site.baseurl }}/img/test.png" %}

但是,这会导致 Liquid 抛出错误:

  Liquid Exception: Invalid syntax for include tag: ... 
" Valid syntax: {% include file.ext param='value' param2='value' %} in
bundler: failed to load command: jekyll (/usr/local/lib/ruby/gems/2.6.0/bin/jekyll)

我认为问题是由于我在content 参数中包含了{{ site.baseurl }}

我怎样才能绕过这个限制?

【问题讨论】:

    标签: html ruby jekyll liquid


    【解决方案1】:

    https://jekyllrb.com/docs/includes/#passing-parameter-variables-to-includes

    发布后不久,我在 Jekyll 文档中找到了答案。

    content 参数的值应在将其传递给包含之前单独存储为变量,使用capture。对于上面的例子:

    {% capture callout_content %}
    Content to be filled with a URL: {{ site.baseurl }}/img/test.png
    {% endcapture %}
    
    {% include callout.html content=callout_content %}
    

    【讨论】:

      猜你喜欢
      • 2013-01-07
      • 2018-11-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-28
      • 2016-06-05
      • 1970-01-01
      • 2014-02-04
      相关资源
      最近更新 更多