Reputation: 33
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
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
Reputation: 2591
Capturing the pubyear is vaild but you can also assign pubyear with no spaces.
{% assign pubyear = post.date | date: "%Y" %}
Upvotes: 1