Is there a way to compare two variables in the Template Toolkit?

[% IF OrgType.id == Organization.org_type_id %]selected="selected"[% END %] 

It doesn’t work even if both of them rate the same number.

 [% IF OrgType.id == 3 %]selected="selected"[% END %] 

(i.e., hardcoding in quantity for testing purposes).

 [% OrgType.id %] and [% Organization.org_type_id %] 

both print "3" on the page.

+4
source share
1 answer

The following works for me:

  my $tt = Template->new; $tt->process( \"[% IF foo == bar %]blah[% END %]", { foo => 42, bar => 42 } ); 

This displays a blah. Therefore, I suspect that your two variables do not contain what you think they are doing. The Template Toolkit uses string equality for == , so if you do:

  my $tt = Template->new; $tt->process( \"[% IF foo == bar %]blah[% END %]", { foo => 42, bar => "42 " } ); 

He will break. You may need to massage the data a bit to make it work correctly with row equality.

+10
source

Source: https://habr.com/ru/post/1301072/


All Articles