Jarvis Jarvis - 25 days ago 12
Twig Question

How to add class if single tag?

I have 4

<li></li>
, which are showed or not.

{% if li == 1 %}{% endif %}


How to add class if only one (single)
<li></li>
is showed?

Answer

You could achieve this slightly differently by applying the style only when the element is the single child of it's parent (only one is rendered)

ul li:only-child {
property: value;
}

link to w3schools article here

Comments