NVelocity - Only show row if not null
Asked Answered
C

2

8

I have the following in my NVelocity template:

#if($PO.GiftMessage != '')
<tr>
    <td align="left">
      <font face="arial" size="2" color="#000000">
        <b>Gift Message</b>
        <br />
        $PO.GiftMessage
      </font>
    </td>
</tr>
#end

Basically if my object (PO) has the property GiftMessage, and it is not null, i want to display that tr.... It's not currently working - Have i got my syntax wrong?

Comatose answered 5/10, 2009 at 17:17 Comment(0)
C
8

I ended up using this...

#if($PO.GiftMessage) 
    #if($PO.GiftMessage !="")
         ...whatever....
    #end
#end

Basically this line:

if($PO.GiftMessage)

returns "true" if $PO.GiftMessage is not null (this could still be a string.empty value, hence my nested if statement below it)

Comatose answered 7/10, 2009 at 11:20 Comment(0)
S
0

it would be cleaner to put it in a single IF statement

#if($PO.GiftMessage && $PO.GiftMessage !="")
      ...whatever....
#end
Stickweed answered 10/5, 2012 at 14:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.