0

I'm trying to create a nested if condition using velocity template. I am not sure if it is right. Please give the suggestions if it works or not..!!

#if(myExpression1)
#if(myExpression2)
 Result 1
#else
  Result 2
#end
#else
  Result 3
#end
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Sabari Dheera
  • 43
  • 1
  • 5

2 Answers2

1

Yes this works. You can nest an if within an if. Just make sure that all #if statements are closed with an #end

There are some examples of nested statements within default hybris. For example in copyable-template.vm

#if ($hasEqualsProperties)
    <code>
    #if ($superEquals)
        <code>
    #end
    <code>
    #foreach($v in $equalsProperties)
        #if ($v.type == 'boolean')
            <code>
        #else
            <code>
        #end
    #end
#end

For simplicity, I've removed some of the code and only left the # statements in

Yoni
  • 1,370
  • 7
  • 17
0

We can do all kinds of conditional operations just an example here.

#if ( $ctx.isGuest() )
        #set ($orderInfoUrl = "${ctx.baseUrl}/guest/order/${ctx.orderGuid}")
    #else
        #set ($orderInfoUrl = "${ctx.baseUrl}/my-account/order/${ctx.orderCode}")
    #end
Raushan Kumar
  • 1,195
  • 12
  • 21