Alex Rivera | Logout

Testing variable equality in twig

Asked 2010-11-29T11:03:04.850
46

In twig, is there an easy way to test the equality of 2 variables?

{% if var1 = var2 %} isn't valid, {% if var1 is sameas(var2) %} only works if both are a strings...

(from docs) "sameas checks if a variable points to the same memory address than another variable", like thats useful.

So the only way I've found of comparing integers is to convert them both to strings:
{% if var1|lower is sameas(var2|lower) %}

Edit
Report

1 Answer

1

If you are comparing value which have a numeric value you can use:

{% if (psong.songid) ==(song.id) %}
answered 2013-02-06T10:11:07.027

Your Answer