문제

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>
도움이 되었습니까?

해결책 2

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.

다른 팁

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top