🔥 Black Friday: Up to 50% Off All Plans
Days
Hrs
Min
Sec

Need Help?

Here are some good places you cant start.

Whats New?

Get updated about all the good stuff!

wordpress-black-friday-deals-2025
Unlimited Elements for Elementor – Version 2.0
Unlimited Elements for Elementor – Version 2.0

Twig Code Example – If Else Elseif

Use an IF – Elseif – Else condition in Twig when there are more than two cases. Twig checks the conditions in order and shows the HTML of the first condition that is true. You can add this code from Twig Code Examples > IF – Else – Elseif in the widget creator. To learn how, see Showing twig code examples.

				
					{% if product_stock == 0 %}
	<!-- put your 0 html here -->
{% elseif product_stock > 0 and product_stock < 20 %}
	<!-- put your 0-20 html here -->
{% elseif product_stock >= 20 %}
	<!-- put your >20 html here -->
{% endif %}
				
			

In this example, product_stock is the name of an attribute. The first part is shown when the value is 0, the second part when it is between 0 and 20, and the third part when it is 20 or more. You can add as many {% elseif %} parts as you need.

To show HTML when none of the conditions is true, add {% else %} before {% endif %}. For example, with a Dropdown attribute:

				
					{% if icon_position == "left" %}
	<div class="my-box my-box--left">...</div>
{% elseif icon_position == "right" %}
	<div class="my-box my-box--right">...</div>
{% else %}
	<div class="my-box">...</div>
{% endif %}
				
			

Hurray!

You got FREE access to the worlds leading widgets for Elementor page builder!

Download is just a click away

Get instant access to tons of Elementor goodies, completely FREE!