Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony Twig Template: string comparison first converting to lower case

Tags:

php

twig

symfony

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!

like image 324
user702300 Avatar asked Dec 25 '22 12:12

user702300


1 Answers

{% 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" %}
like image 58
Paul Avatar answered Jan 30 '23 06:01

Paul