Hi, I'm David Askew

I build things


Contact Me


Open Source

Liquid Case Statement Example

I use Jekyll to create a mostly static website. I also use some Liquid templates to add dynamic elements to my otherwise static site. I was trying to figure out how to iterate over all the posts on my site and take action on only those posts from 2014.

Below is an example of printing ‘hello world’ for every post with a post date in 2014.

{% for post in site.posts %}
  {% assign y = | date: "%Y" %}
  {% case y %}
    {% when '2014' %}
      <li>Hello World </li>
  {% endcase %}
{% endfor %}

I hope this helps you.