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
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
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
We can do all kinds of conditional operations just an example here.