【问题标题】:Render markdown specified in Jekyll/liquid for loop在 Jekyll/liquid for 循环中指定的渲染降价
【发布时间】:2023-03-16 06:41:02
【问题描述】:

我正在尝试抓取 Jekyll 页面前面指定的文件,然后在我的模板中呈现 markdown。

当 yaml 中只有一个键时,这才有效,但我将其更改为循环,现在我无法让它呈现降价。它只是吐出值,实际上并没有对它们进行降价。

我的 yaml 看起来像这样:

additional_sidebar:
  - editorial-extra.md
  - editorial-extra-2.md

我的液体看起来像这样:

{% for sidebar in page.additional_sidebar %}

  {% capture sidebar %}{% include {{ sidebar }} %}{% endcapture %}
  <section class="aside">
    {{ sidebar | markdownify }}
  </section>

{% endfor %}

结果是它只是吐出值,而不是渲染降价:

社论-extra.md editorial-extra-2.md

作为参考,这是我原来的工作代码:

yaml:

additional_sidebar: editorial-extra.md

液体:

{% if page.additional_sidebar %}

  {% capture additional_sidebar %}{% include {{ page.additional_sidebar }} %}{% endcapture %}
  <section class="aside aside-scroll fixedsticky">
    {{ additional_sidebar | markdownify }}
  </section>

{% endif %}

【问题讨论】:

    标签: yaml jekyll liquid


    【解决方案1】:

    您的流动代码中有竞争条件。您在循环和捕获中使用 sidebar 变量。只需在捕获中更改 sidebarmdsidebar

    {% for sidebar in page.additional_sidebar %}
    
      {% capture sidebarmd %}{% include {{ sidebar }} %}{% endcapture %}
      <section class="aside">
        {{ sidebarmd | markdownify }}
      </section>
    
    {% endfor %}
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-07
      • 2021-10-07
      • 2017-12-30
      • 2018-01-16
      相关资源
      最近更新 更多