You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by newbie-gero <ch...@e7tech.com> on 2008/05/29 12:53:27 UTC

How to use the if else statement in velocity

Greetings, i'm using the if else statement to select which text to display.
Below are my codes :

There are 3 types of values in my arrayList for the variable delivery:
courier, mail or register mail.
This is how i display the values

#foreach ( $email in $orderList)
$email.deliver (this code will display which type of delivery)
#end

So right now, i'm trying to display out some text which depends on which
type of delivery. This is how i write in the velocity template


#foreach ( $email in $orderList)

#set($email.deliver = "courier")
#if ($email.deliver)
This is courier delivery
#end

#set($email.deliver = "mail")
#if ($email.deliver)
This is mail delivery
#end

#set($email.deliver = "register mail")
#if ($email.deliver)
This is reigister delivery
#end

However it displays all the 3 text even when i set the if statement. Where
have i gone wrong? 
Thanks for the guidance in advance


-- 
View this message in context: http://www.nabble.com/How-to-use-the-if-else-statement-in-velocity-tp17532430p17532430.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: How to use the if else statement in velocity

Posted by ap...@recks.org.
Hi,

your #if statement just checks the existence of a $email.deliver value (non-null, non-boolean-false and not-empty-string). I beleive you want the following:

#foreach ( $email in $orderList)
#if($email.deliver == "courier")
This is courier delivery
#elseif($email.deliver == "mail")
This is mail delivery
#elseif($email.deliver == "register mail")
This is reigister delivery
#end
#end

Cheers,
Christoph

newbie-gero wrote:
> Greetings, i'm using the if else statement to select which text to display.
> Below are my codes :
> 
> There are 3 types of values in my arrayList for the variable delivery:
> courier, mail or register mail.
> This is how i display the values
> 
> #foreach ( $email in $orderList)
> $email.deliver (this code will display which type of delivery)
> #end
> 
> So right now, i'm trying to display out some text which depends on which
> type of delivery. This is how i write in the velocity template
> 
> 
> #foreach ( $email in $orderList)
> 
> #set($email.deliver = "courier")
> #if ($email.deliver)
> This is courier delivery
> #end
> 
> #set($email.deliver = "mail")
> #if ($email.deliver)
> This is mail delivery
> #end
> 
> #set($email.deliver = "register mail")
> #if ($email.deliver)
> This is reigister delivery
> #end
> 
> However it displays all the 3 text even when i set the if statement. Where
> have i gone wrong? 
> Thanks for the guidance in advance
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: How to use the if else statement in velocity

Posted by ap...@recks.org.
Hi,

your #if statement just checks the existence of a $email.deliver value (non-null, non-boolean-false and not-empty-string). I beleive you want the following:

#foreach ( $email in $orderList)
#if($email.deliver == "courier")
This is courier delivery
#elseif($email.deliver == "mail")
This is mail delivery
#elseif($email.deliver == "register mail")
This is reigister delivery
#end
#end

Cheers,
Christoph

newbie-gero wrote:
> Greetings, i'm using the if else statement to select which text to display.
> Below are my codes :
> 
> There are 3 types of values in my arrayList for the variable delivery:
> courier, mail or register mail.
> This is how i display the values
> 
> #foreach ( $email in $orderList)
> $email.deliver (this code will display which type of delivery)
> #end
> 
> So right now, i'm trying to display out some text which depends on which
> type of delivery. This is how i write in the velocity template
> 
> 
> #foreach ( $email in $orderList)
> 
> #set($email.deliver = "courier")
> #if ($email.deliver)
> This is courier delivery
> #end
> 
> #set($email.deliver = "mail")
> #if ($email.deliver)
> This is mail delivery
> #end
> 
> #set($email.deliver = "register mail")
> #if ($email.deliver)
> This is reigister delivery
> #end
> 
> However it displays all the 3 text even when i set the if statement. Where
> have i gone wrong? 
> Thanks for the guidance in advance
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: How to use the if else statement in velocity

Posted by newbie-gero <ch...@e7tech.com>.
Oh yes.. Thanks for the guidance..



apache-10 wrote:
> 
> Hi,
> 
> your #if statement just checks the existence of a $email.deliver value
> (non-null, non-boolean-false and not-empty-string). I beleive you want the
> following:
> 
> #foreach ( $email in $orderList)
> #if($email.deliver == "courier")
> This is courier delivery
> #elseif($email.deliver == "mail")
> This is mail delivery
> #elseif($email.deliver == "register mail")
> This is reigister delivery
> #end
> #end
> 
> Cheers,
> Christoph
> 
> newbie-gero wrote:
>> Greetings, i'm using the if else statement to select which text to
>> display.
>> Below are my codes :
>> 
>> There are 3 types of values in my arrayList for the variable delivery:
>> courier, mail or register mail.
>> This is how i display the values
>> 
>> #foreach ( $email in $orderList)
>> $email.deliver (this code will display which type of delivery)
>> #end
>> 
>> So right now, i'm trying to display out some text which depends on which
>> type of delivery. This is how i write in the velocity template
>> 
>> 
>> #foreach ( $email in $orderList)
>> 
>> #set($email.deliver = "courier")
>> #if ($email.deliver)
>> This is courier delivery
>> #end
>> 
>> #set($email.deliver = "mail")
>> #if ($email.deliver)
>> This is mail delivery
>> #end
>> 
>> #set($email.deliver = "register mail")
>> #if ($email.deliver)
>> This is reigister delivery
>> #end
>> 
>> However it displays all the 3 text even when i set the if statement.
>> Where
>> have i gone wrong? 
>> Thanks for the guidance in advance
>> 
>> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
> For additional commands, e-mail: user-help@velocity.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-to-use-the-if-else-statement-in-velocity-tp17532430p17549848.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org


Re: How to use the if else statement in velocity

Posted by ap...@recks.org.
Hi,

your #if statement just checks the existence of a $email.deliver value (non-null, non-boolean-false and not-empty-string). I beleive you want the following:

#foreach ( $email in $orderList)
#if($email.deliver == "courier")
This is courier delivery
#elseif($email.deliver == "mail")
This is mail delivery
#elseif($email.deliver == "register mail")
This is reigister delivery
#end
#end

Cheers,
Christoph

newbie-gero wrote:
> Greetings, i'm using the if else statement to select which text to display.
> Below are my codes :
> 
> There are 3 types of values in my arrayList for the variable delivery:
> courier, mail or register mail.
> This is how i display the values
> 
> #foreach ( $email in $orderList)
> $email.deliver (this code will display which type of delivery)
> #end
> 
> So right now, i'm trying to display out some text which depends on which
> type of delivery. This is how i write in the velocity template
> 
> 
> #foreach ( $email in $orderList)
> 
> #set($email.deliver = "courier")
> #if ($email.deliver)
> This is courier delivery
> #end
> 
> #set($email.deliver = "mail")
> #if ($email.deliver)
> This is mail delivery
> #end
> 
> #set($email.deliver = "register mail")
> #if ($email.deliver)
> This is reigister delivery
> #end
> 
> However it displays all the 3 text even when i set the if statement. Where
> have i gone wrong? 
> Thanks for the guidance in advance
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org