2

我的 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 提要:为帖子生成提要 Liquid 异常:Liquid 语法错误(/home/xxxxx/repositories/legal/_includes/_head.html 第 100 行):“for”标签从未关闭包含在 /_layouts/default.html 中错误:Liquid语法错误(/home/xxxx/repositories/legal/_includes/_head.html 第 100 行):“for”标签从未关闭包含错误:运行 jekyll build --trace 以获取更多信息。

线: 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 %}

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

4

2 回答 2

1

在我对 Jekyll 3.8.5 和 Jekyll 4.0.0 的测试中,这两个场景都像一个魅力,没有错误,没有限制:

如果别的:

{% 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 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 异常:Liquid 语法错误(C:/Users/User/Desktop/ruby_projects/jekyll_test/testpage/_includes/3.html 第 9 行):“for”标签从未关闭包含在 /_layouts/default.html jekyll 3.8.6 中| 错误:Liquid 语法错误(C:/Users/User/Desktop/ruby_projects/jekyll_test/testpage/_includes/3.html 第 9 行):“for”标签从未关闭包含

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

于 2019-09-17T20:54:21.683 回答
0

文件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 %}
     ],

于 2019-09-15T01:57:34.827 回答