Mil*_*loš 1 if-statement symfony twig
我想为每个偶数行创建一个不同颜色的表.为此,我创建了css,如果迭代索引是偶数,我将不得不检查我的twig模板.
{% if loop.index == "even" %}
Run Code Online (Sandbox Code Playgroud)
但是如何检查一个数字是否在树枝上?谢谢.
Twig有一个内置的"偶数"测试:
{% if (loop.index is even) %}
...your code here
{% endif %}
Run Code Online (Sandbox Code Playgroud)
您必须使用“模”运算符,如下所示:
{% if(loop.index%2 == 0) %}
...your code here
{% endif %}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3575 次 |
| 最近记录: |