The result of what I was expecting is not the desired one..
The output of the table, is messing up because of it.
so… the code is this one:
{% if (log.action) == "update"%}
<td style="width: 150px; background-color: yellow;" >{{log.action}}
{% else %}
{% if (log.action) == "insert"%}
<td style="width: 150px; background-color: green;" >{{log.action}}
{% endif %}
<td style="width: 150px; background-color: red;" >{{log.action}}
{% endif %}
and what I need from it is just to print with background-color when the output string is equal to those 3 options (only those are the options).
2
Answers
The current structure leads to rendering multiple
<td>
tags for the same condition, causing the output to be messy. Instead of above code, use single<td>
for all your conditions.Instead of nesting
if
‘s inside each other, consider an actual{% if %}...{% elseif %}..{% endif %}
-structuredemo
A more clean solution would be to extend
Twig
and add a custom function/filter, e.g.You could also drop the inline CSS and use classes of course e.g.