如何在Liquid中对转换为数组的哈希进行排序 [英] How to sort a hash converted to an array in Liquid
问题描述
我的理解是Liquid将Ruby Hashes转换为数组以用于标签.例如,当使用Jekyll时:
My understanding is that Liquid converts Ruby Hashes to arrays for use in tags. For example, when using Jekyll:
{% for category in site.categories %}
<li>{{ category[0] }}</li>
{% endfor %}
...将site.categories转换为元组数组,其中[0]引用键,[1]值列表.
... converts site.categories to an array of tuples in which [0] refers to the key, [1] the list of values.
如果我希望以上类别映射按键(每个元组的[0])按字母顺序排序,怎么办?
If I wanted the above category map to be sorted alphabetically by the key ([0] of each tuple) how can I do this?
推荐答案
默认的Liquid实现或Jekyll所做的添加都无法满足您的需求.
Neither the default Liquid implementation nor the additions made by Jekyll allow for what you want.
恐怕当前设置根本无法满足您的需求.您必须先对Jekyll或Liquid进行修补,才能使散列按排序顺序返回其密钥.
I'm afraid what you want is simply not possible with the current setup. You would have to monkeypatch Jekyll or Liquid in order to make the hashes return their keys in a sorted order.
这篇关于如何在Liquid中对转换为数组的哈希进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!