Denver Prophit Jr.
Denver Prophit Jr.

Reputation: 164

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

My Jekyll version is 3.8.6.

If I have too many elseif I get a for logic error where no for loop was written. If I remove one elseif, it works.

This does not work:

{% 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 %}

This Works!

{% 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 %}

The error I get with the additional elsif is

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.

Line: 100 is {% elsif page.jsontype == "lawyer" %}.

Edit 1:

I have got the same error when using 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 %}

It still shows the same error pointing to the end of the head file.

Upvotes: 2

Views: 3254

Answers (2)

Denver Prophit Jr.
Denver Prophit Jr.

Reputation: 164

The file collectionJSONLD.html was missing {% 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 %}
     ],

Upvotes: 0

Christian
Christian

Reputation: 5531

In my tests with Jekyll 3.8.5 and Jekyll 4.0.0 both scenarios worked like a charm, no errors, no limitations:

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

Any missing {% endfor %}, also within the includes files, showed the same error message but the correct line:

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

One of my last thoughts was that you added and removed a specific page, e.g. collectionJSONLD.html every time when testing this (as you confirmed). There must be a specific thing we can't see as you haven't posted the complete code of the project. Nevertheless, great to read that you solved it! This was a hard one :)

Upvotes: 1

Related Questions