Reputation: 21
I have the following YML code that I am trying to sort alphabetically
in Jekyll:
layout: project
title: Home renovation
link: http://urlgoeshere.com
builtWith:
- Concrete
- Glass
- Brick
- Dirt
Here is my template code:
<h4>Built With</h4>
<ul class="list-unstyled list-inline list-responsibilities">
{% for item in page.builtWith %}
<li>{{ item }}</li>
{% endfor %}
</ul>
What do I need to add to the for
loop to get the builtWith
items to sort alphabetically
?
Thanks!
Upvotes: 1
Views: 633
Reputation: 23972
In the latest Jekyll version, using just sort
tag doesn't work because you need to assign it to a variable first: Liquid Warning: Liquid syntax error (line 24): Expected end_of_string but found pipe in "item in page.builtWith | sort"
.
If you are not using the latest version then it can work adding sort
in the same line.
Using assign
and sort
tags is safer:
<h4>Built With</h4>
<ul class="list-unstyled list-inline list-responsibilities">
{% assign sorted = page.builtWith | sort %}
{% for item in sorted %}
<li>{{ item }}</li>
{% endfor %}
</ul>
Outputs:
Built With
Brick
Concrete
Dirt
Glass
Upvotes: 0
Reputation: 12391
Try this
{% assign sorted = (page.builtWith | sort) %}
{% for item in sorted %}
Upvotes: 1