Trabla: Twig & php: count elements in array
Solving:
Use length filter
Example:
{% if items|length > 0 %}
<table>
<tr>
<td>Name</td>
<td>Value</td>
</tr>
{% for item in items %}
<tr>
<td> {{item.name}} </td>
<td> {{item.value}} </td>
</tr>
{% endfor %}
</table>
{% endif %}
Where items - array of assoc arrays:
[
[ "name" => "Test1" , "value" => "Passed" ],
[ "name" => "Test2", "value " => "Failed" ]
]
No comments:
Post a Comment