你好,我想做那样的事情:
<?php $count = 0; foreach($a as $v): $count++; ?>
<?php if ($count%2 == 0): ?>
...
<?php endif; ?>
<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)
在树枝上:
{% for v in a %}
{% if ??? is even %}
...
{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
但是我如何才能使用循环变量?
vst*_*stm 62
显然twig 在for循环中定义了一些循环变量:
{% for v in a %}
{% if loop.index0 is even %}
...
{% endif %}
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
Ant*_*lqk 24
如果您使用它进行样式设置,您可以:
{% for v in a %}
<div class="link {{ cycle(['even', 'odd'], loop.index0) }}">
</div>
{% endfor %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
41584 次 |
| 最近记录: |