簡體   English   中英

如何在液體模板中拆分數組?

[英]How to split an array in liquid templates?

我有一個看起來像這樣的數組。

my_array = [
    {'first': 'foo'},
    {'second': 'bar'},
    {'third': 'baz'},
    {'fourth': 'qux'}
]

我正在嘗試使用液體模板渲染前兩個項目。 如何不使用索引就實現此目標?

謝謝。

您可以使用limit標簽

{% for thing in my_array limit:2 %}
   <p>{{thing.whatever}}</p>
{% endfor %}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM