How to use the if else statement in velocity

View: New views
5 Messages — Rating Filter:   Alert me  

How to use the if else statement in velocity

by newbie-gero :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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


Re: How to use the if else statement in velocity

by apache-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
For additional commands, e-mail: user-help@...


Re: How to use the if else statement in velocity

by apache-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
For additional commands, e-mail: user-help@...


Re: How to use the if else statement in velocity

by apache-10 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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@...
For additional commands, e-mail: user-help@...


Re: How to use the if else statement in velocity

by newbie-gero :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

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