Is there any way to implement nested if else functionality in twig? I have tried the following but it isn't working:
<body {% if page|default('login') == 'login' %} class="login" {% else if( page == 'other') %} class="login" {% else %} class="noclass" {% endif %}> </body>
Twig != is a comparison operator. You can use != to compare any two things that php lets you compare, and what you get back is a boolean.
elseif
needs to be single word tag/keyword and expression shouldn't have parenthesis same as if
expression.
http://twig.sensiolabs.org/doc/tags/if.html
<body {% if page|default('login') == 'login' %} class="login" {% elseif page == 'other' %} class="login" {% else %} class="noclass" {% endif %}> </body>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With