Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jekyll variables, if functions

Tags:

jekyll

liquid

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 -->
like image 547
wwwSammy Avatar asked Apr 20 '26 07:04

wwwSammy


1 Answers

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>
like image 160
marcanuy Avatar answered Apr 22 '26 02:04

marcanuy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!