代码之家  ›  专栏  ›  技术社区  ›  Alex

nvelocity-仅在不为空时显示行

  •  8
  • Alex  · 技术社区  · 15 年前

    我的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
    

    基本上,如果我的对象(po)具有属性giftmessage,并且它不是空的,我希望显示该tr…。 它目前不工作- 我的语法有错吗?

    2 回复  |  直到 12 年前
        1
  •  8
  •   bernhof    12 年前

    我最后用了这个…

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

    基本上这一行:

    if($PO.GiftMessage)
    

    如果$po.giftmessage不为空,则返回“true”(这可能仍然是string.empty值,因此它下面是我的嵌套if语句)

        2
  •  0
  •   BikerP    12 年前

    把它放在一个if语句中会更干净

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