Answers for "twig switch case"

PHP
-1

twig switch case

// There is no switch statement... use if - elseif instead
{% if condition %}
...
{% elseif condition2 %}
...
{% else %}
...
{% endif %}

/*
Some sites like 
	https://www.branchcms.com/learn/docs/developer/twig/tags/item/switch
define switch as follows, but it doesn't render...

{% set value = 'value2' %}
{% switch value %}
    {% case 'value1' %}
        <p>value is "value1"</p>
    {% case 'value2' %}
        <p>value is "value2"</p>
    {% case 'value3' %}
    {% case 'value4' %}
        <p>value is "value3" or "value4"</p>
    {% default %}
        <p>value is something else</p>
{% endswitch %}
*/
Posted by: Guest on June-17-2021

Browse Popular Code Answers by Language