Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Order an array with Jekyll / liquid template

Tags:

jekyll

liquid

I'm trying to do the following. I use Jekyll to create a list of posts, and ordertem by category (monday...sunday) I'd like to have them displayed in chronological order but Jekyll order them alphabetically.

Is it possible to sort an arry with Jekyll?

I have added an order key to the post yaml to mirror monday = 1 ... sunday = 7

I'm trying to then sort the array with this order key, bu it doesn't work.

  {% for post in posts_collate  %}
    {% capture class %} {{ post.tags | first }} {% endcapture%}
    {% capture club %} {{ post.tags | last }} {% endcapture%}

    {% if forloop.first %}
      <h2>our events</h2>
      <h3>{{ class }} & {{ club }}</h3>
      <dl>
    {% endif %}
    {% if post.rel == 'me' %}
      <dt>{{ post.category | sort: 'order' }}</dt> 
      <dd> <a href="{{ BASE_PATH }}{{ post.url }}">{{ post.title }}</a></dd>
    {% endif %}

    {% if forloop.last %}
      </dl>
    {% endif %}
  {% endfor %}

And i can't find any info in the big google machine, so i'm not sure thay it is possible.

like image 214
Yannick Schall Avatar asked Feb 09 '12 21:02

Yannick Schall


1 Answers

It cannot be done without a plugin or custom function. Although, there is an ongoing effort to implement this in the next releases: https://github.com/Shopify/liquid/pull/101 and then it would look like:

{% for tag in site.tags order:ascending %} 
   ...
{% endfor %}
like image 167
lzap Avatar answered Oct 07 '22 22:10

lzap