2016-07-28 57 views
0

我有一個看起來像這樣的數組。如何在液體模板中分割數組?

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

我想呈現使用液體模板的前兩項。我如何在不使用索引的情況下實現這一目標?

謝謝。

回答

0

您可以使用limit tag

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