PDA

View Full Version : vb:if condition problem


MaryTheG(r)eek
24 Dec 2009, 06:25
Hello all,

Does anybody knows what's wrong with:

<vb:if condition="{vb:raw item_premium}==1">checked</vb:if>


Thank you in advance
Maria

BBR-APBT
24 Dec 2009, 14:45
<vb:if condition="$item_premium =='1'">CHECKED</vb:if>
OR
<vb:if condition="$item_premium ==1">CHECKED</vb:if>


I don't remember lol but its one of those.
don't forget to register $item_premium.

MaryTheG(r)eek
24 Dec 2009, 15:31
<vb:if condition="$item_premium =='1'">CHECKED</vb:if>
OR
<vb:if condition="$item_premium ==1">CHECKED</vb:if>


I don't remember lol but its one of those.
don't forget to register $item_premium.

Yes, this syntax is the correct. I tried it and works, but I'm really greatfull for your reply. Finally, as I understood, the syntax vb:raw item_premium is to be used only when we need to print something to screen, while the old way $item_premium is valid for hidden values, condititions, etc.

Merry Christmas to you and to your family
Maria

consolegaming
25 Dec 2009, 12:21
Yes, this syntax is the correct. I tried it and works, but I'm really greatfull for your reply. Finally, as I understood, the syntax vb:raw item_premium is to be used only when we need to print something to screen, while the old way $item_premium is valid for hidden values, condititions, etc.

Merry Christmas to you and to your family
Maria

Yup, that caught me out too. I'd bet they'll change to that syntax in the future because it doesn't really make sense to have two different types of syntax. It'd be best though if they made it compatible with both to allow some backward compatibility.

James Birkett
25 Dec 2009, 13:02
<vb:if condition="$item_premium =='1'">CHECKED</vb:if>
OR
<vb:if condition="$item_premium ==1">CHECKED</vb:if>


I don't remember lol but its one of those.
don't forget to register $item_premium.

Yeah, remember that in conditions you use the dollar variable rather than a vb: variable.

Also, the first option would check if $item_premium is equal to the string 1, whereas the second would check if $item_premium is equal to the boolean 1 (i.e. "true").

consolegaming
26 Dec 2009, 18:40
Yeah, remember that in conditions you use the dollar variable rather than a vb: variable.

Also, the first option would check if $item_premium is equal to the string 1, whereas the second would check if $item_premium is equal to the boolean 1 (i.e. "true").

Wouldn't it only do that if he had three equals? In php I ma under the assumption that == '1' is the same as == 1. You'd need to do === 1 for numbers, === '1' for string and === true for boolean as far as I know.

James Birkett
26 Dec 2009, 23:36
I've managed to use 2 equals signs for boolean in the past via PHP.

I'm not sure about conditions, but I've used it in PHP before.

consolegaming
26 Dec 2009, 23:49
It would match booleans yes but it would also match the string or number representation. == in PHP is non type specific. i.e. it looks for values that match without checking the types. You use === if you want to make sure the type is the same as well i.e. both sides of the conditional are boolean or numerical etc. So if you wanted to make sure that something was true but not the number 1 or '1' then you'd need to do: if ($condition === true) because if you just had == then it would match with '1' or 1 too.

I barely ever need to check that the type matches as well but I thought it best to point that out.