Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ループが3の場合、サイクルを停止したい。 配列に5つのレコードがある場合、3つのレコードのみを表示する必要があります。
{% for image in post.images %} {% if loop.index < '3' %} {{ loop.index}} {% endif %} {% endfor %}
だから私は3つのループだけを表示したい
1 2 3
{% for image in post.images|slice(0, 3) %}
解決した
twig で for ステートメントと if ステートメントを組み合わせることができます。以下のようなものは機能しますが、最終的に出力するのは実際にはループ インデックスではないと思いますか?
{% for image in post.images if loop.index <= 3 %} {{ loop.index }} {% endfor %}