I have the following code for PHP
$option = "yes";
and Twig tag
{% if option == "yes" %}
it works fine, but it fails if capitalized
$option = "YES";
I tried the following but it doesn't work
{% if option == "yes" | lower %}
Any other way? Can't seems to find this from the Twig documentation, thanks!
{% if option == "yes" | lower %}
is the same as {% if option == "yes" %}
, because you are converting the string "yes" to lowercase, which it already is. You want to convert the variable to lowercase instead and then compare them:
{% if option|lower == "yes" %}
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