wwwSammy
wwwSammy

Reputation: 33

jekyll variables, if functions

Why is something like this not working ? i try to filter all posts from this year

<div class="tiles">
{% for post in site.categories.articles %}

  {% capture pubyear %} {{ post.date | date: "%Y" }} {% endcapture %}

    {% if pubyear == "2014" %}
      {% include post-grid.html %}
    {% endif %}

{% endfor %}
</div><!-- /.tiles -->

Upvotes: 3

Views: 309

Answers (2)

marcanuy
marcanuy

Reputation: 23942

The problem is that it is capturing the output with some spaces in it, so it fails the if condition, remove those spaces and it should work

<div class="tiles"> 
  {% for post in site.categories.articles %}
    {% capture pubyear %}{{ post.date | date: "%Y" }}{% endcapture %} 
    {% if pubyear == "2014" %} 
      {% include post-grid.html %} 
    {% endif %}
  {% endfor %}
</div>

Upvotes: 1

GeorgeButter
GeorgeButter

Reputation: 2591

Capturing the pubyear is vaild but you can also assign pubyear with no spaces.

{% assign pubyear = post.date | date: "%Y" %}

Upvotes: 1

Related Questions