开发者

NVelocity - Only show row if not null

开发者 https://www.devze.com 2022-12-08 06:18 出处:网络
I have the following in my NVelocity template: #if($PO.GiftMessage != \'\') <tr> <td align=\"left\">

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>
        &l开发者_JAVA技巧t;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?


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)


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

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

精彩评论

暂无评论...
验证码 换一张
取 消