0
votes

I have some language in a series.html file located in the _includes section of my jekyll blog, pasted below:

{% if page.series %}
{% assign count = '0' %}
{% assign idx = '0' %}
{% for post in site.posts reversed %}
    {% if post.series == page.series %}
        {% capture count %}{{ count | plus: '1' }}{% endcapture %}
        {% if post.url == page.url %}
            {% capture idx %}{{count}}{% endcapture %}
        {% endif %}
    {% endif %}
{% endfor %}
{% endif %}

While it does connect the posts that are designated as part of a series within the post's YAML layout, it also connects other posts as part of a series as well even though they are not designated as 'series' in the YAML front matter of the post, despite the if statement. This results in all of my posts being part of a general "series" which I do not want. I just want to designate some posts to be part of a series while others are just unique one-off posts.

I have tried the following:

  1. Not specifying a series at all within the YAML front matter
  2. setting series: False
  3. setting series: None
1

1 Answers

1
votes

EDIT :

What's actually happening in your post.html template is that not all your html is conditionally printed.

Everything in _includes/series.html is conditioned by page.series != null, but the content of your <div class="panel seriesNote"> is always printed.

You need to move this code (all <div class="panel seriesNote">[...]</div>) in your condition in _includes/series.html.

{% if page.series != null %}
[...]
{% endfor %}
<div class="panel seriesNote">  <<<< moved code
[...]
</div>                          <<<< end moved code
{% endif %}

END EDIT

If you don't set series in your front matter, page.series is nil.

If you leave it empty, it's also nil.

So, {% if page.series != null %} will help you select only pages where series is set to a value.

Note about counters :

{% assign count = '0' %} => count is a string

{% capture count %}{{ count | plus: 1 }}{% endcapture %} => count is a string

If you do :

{% assign count = 0 %} => count is an integer

{% assign count = count | plus: 1 %} => count is an integer

Be aware of this when you use you counter in a comparison, it can leads to errors by trying to compare strings and integers.