'for' 标签从未关闭/如果 elsif else 在液体逻辑中包含页面?

'for' tag was never closed / if elsif else in liquid logic to include a page?

我的 Jekyll 版本是 3.8.6。

如果我有太多 elseif,我会得到一个 for 逻辑错误,其中没有写入 for 循环。如果我删除一个 elseif,它会起作用。

这行不通:

{% if page.jsontype == "page" %}
    {% include pageJSONLD.html %}
  {% elsif page.jsontype == "collection" %}
    {% include collectionJSONLD.html %}
  {% elsif page.jsontype == "post" %}
    {% include postJSONLD.html %}
  {% elsif page.jsontype == "about" %}
    {% include aboutJSONLD.html %}
  {% elsif page.jsontype == "lawyer" %}
    {% include lawyerJSONLD.html %}
  {% elsif page.jsontype == "contact" %}
    {% include contactJSONLD.html %}
  {% else %}
    {% include homeJSONLD.html %}
  {% endif %}

这有效!

{% if page.jsontype == "page" %}
    {% include pageJSONLD.html %}
  {% elsif page.jsontype == "post" %}
    {% include postJSONLD.html %}
  {% elsif page.jsontype == "about" %}
    {% include aboutJSONLD.html %}
  {% elsif page.jsontype == "lawyer" %}
    {% include lawyerJSONLD.html %}
  {% elsif page.jsontype == "contact" %}
    {% include contactJSONLD.html %}
  {% else %}
    {% include homeJSONLD.html %}
  {% endif %}

我得到的附加 elsif 的错误是

Jekyll Feed: Generating feed for posts Liquid Exception: Liquid syntax error (/home/xxxxx/repositories/legal/_includes/_head.html line 100): 'for' tag was never closed included in /_layouts/default.html Error: Liquid syntax error (/home/xxxx/repositories/legal/_includes/_head.html line 100): 'for' tag was never closed included Error: Run jekyll build --trace for more information.

第 100 行是 {% elsif page.jsontype == "lawyer" %}

编辑 1:

我在使用case/when

时遇到了同样的错误
{% case page.jsontype %}
  {% when 'page' %}
    {% include pageJSONLD.html %}
  {% when 'collection' %}
    {% include collectionJSONLD.html %}
  {% when 'post' %}
    {% include postJSONLD.html %}
  {% when 'about' %}
    {% include aboutJSONLD.html %}
  {% when 'lawyer' %}
    {% include lawyerJSONLD.html %}
  {% when 'contact' %}
    {% include contactJSONLD.html %}
  {% else %}
    {% include homeJSONLD.html %}
 {% endcase %}

指向头文件末尾,仍然显示相同的错误。

文件 collectionJSONLD.html 丢失 {% endfor %}

{% for member in site.data.members %}
  {
    "@type": "ListItem",
    "name": "{{ member.name }}",
    "url": "{{ member.permalink }}",
    "position": "{{ forloop.index }}"
    {% if forloop.first %}
      },
    {% elsif forloop.last %}
      }
    {% endif %}
{% endfor %}
     ],

在我对 Jekyll 3.8.5 和 Jekyll 4.0.0 的测试中,这两种情况都非常有效,没有错误,没有限制:

If/else:

{% if page.jsontype == "page" %}
    {% include 1.html %}
  {% elsif page.jsontype == "collection" %}
    {% include 2.html %}
  {% elsif page.jsontype == "post" %}
    {% include 3.html %}
  {% elsif page.jsontype == "about" %}
    {% include 4.html %}
  {% elsif page.jsontype == "lawyer" %}
    {% include 5.html %}
  {% elsif page.jsontype == "contact" %}
    {% include 6.html %}
  {% else %}
    {% include 7.html %}
  {% endif %}

Case/When:

{% case page.jsontype %}
  {% when 'page' %}
    {% include 1.html %}
  {% when 'collection' %}
    {% include 2.html %}
  {% when 'post' %}
    {% include 3.html %}
  {% when 'about' %}
    {% include 4.html %}
  {% when 'lawyer' %}
    {% include 5.html %}
  {% when 'contact' %}
    {% include 6.html %}
  {% else %}
    {% include 7.html %}
 {% endcase %}

任何缺失的 {% endfor %},也在包含文件中,显示相同的错误消息,但正确的行:

Liquid Exception: Liquid syntax error (C:/Users/User/Desktop/ruby_projects/jekyll_test/testpage/_includes/3.html line 9): 'for' tag was never closed included in /_layouts/default.html jekyll 3.8.6 | Error: Liquid syntax error (C:/Users/User/Desktop/ruby_projects/jekyll_test/testpage/_includes/3.html line 9): 'for' tag was never closed included

我最后的想法之一是您添加和删除了特定页面,例如collectionJSONLD.html 每次测试时(正如您确认的那样)。 由于您尚未发布项目的完整代码,因此必须有一个特定的东西我们看不到。尽管如此,很高兴看到您解决了它!这是一个艰难的过程:)