NVelocity - 仅在不为空时显示行

Ale*_*lex 8 c# nvelocity

我的NVelocity模板中有以下内容:

#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
Run Code Online (Sandbox Code Playgroud)

基本上如果我的对象(PO​​)具有属性GiftMessage,并且它不是null,我想显示那个tr ....它当前不工作 - 我的语法错了吗?

Ale*_*lex 8

我最终用这个......

#if($PO.GiftMessage) 
    #if($PO.GiftMessage !="")
         ...whatever....
    #end
#end
Run Code Online (Sandbox Code Playgroud)

基本上这一行:

if($PO.GiftMessage)
Run Code Online (Sandbox Code Playgroud)

如果$ PO.GiftMessage不为null,则返回"true"(这可能仍然是一个string.empty值,因此我的嵌套if语句在它下面)