使用 Jekyll / Liquid 模板订购阵列
我正在尝试执行以下操作。 我使用 Jekyll 创建帖子列表,并按类别排序(周一...周日) 我想让它们按时间顺序显示,但 Jekyll 按字母顺序排列。
是否可以使用 Jekyll 对 arry 进行排序?
我已在 post yaml 中添加了一个订单键以镜像 monday = 1 ... sunday = 7
我尝试使用此订单键对数组进行排序,但它不起作用。
{% 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 %}
我在大型谷歌机器中找不到任何信息,所以我不确定这是否可能。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果没有插件或自定义功能,这是无法完成的。尽管如此,我们仍在努力在下一个版本中实现这一点:https://github.com /Shopify/liquid/pull/101 然后它看起来像:
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
语句中添加reversed
即可simply add
reversed
in thefor
statement好吧,不确定是否可以进行这种排序,但我有点作弊
(•__°)
我刚刚将我想要订购的帖子重命名为特定日期,例如:
0000-00-01-firstpost
等等...
现在为我做,但如果有更聪明的方法来做到这一点,我愿意(^___^)
Ok, not sure it is possible at all to do this kind of sorting, but i've cheated a bit
(•__°)
I just renamed the post that i want to be order with a specific date like:
0000-00-01-firstpost
etc...
Does it for me for now, but if there is a more clever way to do that, I'm up for it (^___^)