Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compare string with velocity

Considering the following piece of code in a velocity template:

#set($brandName = $player.brand.name)
#set($brandNameExample = "NameExample")

#if($brandName == $brandNameExample)
    11111
#else
    22222
#end

I always get 22222. Of course, player.brand.name = "NameExample".

Can anybody explain me why and how to get it work please?

like image 627
mordekhai Avatar asked Feb 18 '13 08:02

mordekhai


2 Answers

I would recommend to test this

#set($brandName = "NameExample")
#set($brandNameExample = "NameExample")
#if($brandName == $brandNameExample)
11111
#else
22222
#end

if it works then I would try to output $player, $player.brand, $player.brand.name you need to make sure that $player.brand.name - keeps correct value. - case sensivity? - sure that spell '$player.brand.name' correctly?

I think you simply has problem in object $player

like image 180
Dmytro Pastovenskyi Avatar answered Sep 17 '22 14:09

Dmytro Pastovenskyi


Well I found the solution : I called twice to velocity : the first time without the player object and second one with it. So at the first call all directives concerning player could not be evaluated and returned null. Thank you all for your help

like image 39
mordekhai Avatar answered Sep 18 '22 14:09

mordekhai