【问题标题】:Jekyll treating custom variable in included file as filenameJekyll 将包含文件中的自定义变量视为文件名
【发布时间】:2021-04-22 13:44:48
【问题描述】:

我有一个自定义变量,我将它传递到我的包含文件中,奇怪的是它被视为文件名。我不确定我做错了什么:

我的组件包含:

{% include_relative includes/form/components/modal.html for="purpose" %}

includes/form/components/modal.html的内容是:

<div class="modal-custom modal-custom-white" data-modal-custom="{% include.for %}" data-modal-requires-update-button>
  <div class="modal-custom-background bg-white"></div>
  <div class="modal-custom-content p-3">

    {% if include.title %}
      <h5 class="font-weight-normal text-dark mb-3">{% include.title %}</h5>
    {% else %}
      <h5 class="font-weight-normal text-dark mb-3"><strong>Tap</strong> to choose:</h5>
    {% endif %}

    <!-- Modal content here -->
    {% if include.content %}
      {% include.content %}
    {% endif %}

  </div>
  <button type="button" class="modal-custom-close is-large bg-light" onclick="toggleModal('purpose', 'close-retain');diposeExpandedToggler('purpose', true)"></button>
</div>

我正在运行最新版本的 Jekyll,版本 4.2.0,如果我删除 for,那么一切正常。我试过了:

  • 重命名变量
  • 清理缓存
  • 以不同的方式格式化变量,例如:for=purposefor="purpose"

我在另一个组件中创建了类似的东西,在那里一切正常,但我在这里遇到的错误是:

液体异常:在任何 ["/Users/USER/Sites/MY-PROJECT/src/_includes"] 中都找不到包含的文件 '.for'。确保它存在于这些目录之一中,如果它是符号链接,则不要指向您的站点源之外。在 icicle.html 中

这很奇怪。我错过了什么?

【问题讨论】:

    标签: html jekyll liquid


    【解决方案1】:

    您可能只需要使用输出标签{{ include.for }} 而不是非输出标签{% include.for %}include.titleinclude.content 也是这种情况。

    您应该传递一个不带引号的变量,否则您将传递字符串文字 "purpose" 而不是 purpose 变量保存的值。

    尽管它可能仍然有效,但我会尽可能避免使用 for 作为键,因为它是 Liquid 中使用的 for 循环关键字。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-13
      • 2012-08-25
      • 1970-01-01
      • 1970-01-01
      • 2020-02-19
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      相关资源
      最近更新 更多