I am starting with Liquid & Jekyll can anyone help me with making list order ascending (by {{category}} name)?
<div class="col-xs-6 col-sm-3 patickaborder">
<h5>Rubriky</h5>
<ul>
{% for category in site.categories order:ascending %}
<li><a href="{{ site.url }}{{ category | first }}/index.html">{{ category | first }}</a></li>
{% endfor %}
</ul>
</div>
Just found this out. You can sort the list and assign it to a variable, then use that in your markup, like this:
{% assign sortedcats = site.categories | sort %}
<div class="col-xs-6 col-sm-3 patickaborder">
<h5>Rubriky</h5>
<ul>
{% for category in sortedcats %}
<li><a href="{{ site.url }}{{ category | first }}/index.html">{{ category | first }}</a></li>
{% endfor %}
</ul>
</div>
As far as I know, there's no built-in way for ordering as of now, it's only possible with plugins.
The order:ascending
syntax you're using in your question will maybe work in the future, when this is implemented in Liquid.
In the same question, there's another answer that shows how to sort with a plugin (which means that it won't work on GitHub Pages!).
If you can't use or don't want to use a plugin, it's possible to do it without plugins...with some really ugly looking Liquid-foo.
Check out this answer, where I'm ordering site.tags
alphabetically to create a list of tags for my blog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With