1

Apache Velocity用于创建电子邮件模板。我有一封邮件,其中包含一个包含元素列表的表格,为了创建它,我使用了#foreach.

在此表中,我将添加一个包含条件字符串的列,如果元素为空,则字符串string1is if is not empty are string2

这是我的代码

 #foreach( $item in $list )
        <td style="max-width: 140px; word-wrap: break-word;">
        #if(${value} not null) 'String1' #else 'String2'#end</td>
 #end

错误日志

 org.apache.velocity.runtime.parser.ParseException: Encountered "null" at line 25, column 131. Was expecting one of:
    "[" ...
    "{" ...
    "(" ...
    <STRING_LITERAL> ...
    "true" ...
    "false" ...
    <INTEGER_LITERAL> ...
    <FLOATING_POINT_LITERAL> ...
    <IDENTIFIER> ...
    "{" ...
    "[" ...
        at org.apache.velocity.runtime.parser.Parser.generateParseException(Parser.java:3679)

我在堆栈中找不到任何帮助...有人可以帮助我吗?

4

1 回答 1

2

我认为这可以在您的情况下运行:

#if( $value)
    <td style="max-width: 140px; word-wrap: break-word;">String1</td>
#else
    <td style="max-width: 140px; word-wrap: break-word;">String2</td>
#end

尝试阅读这个问题

于 2018-06-11T11:24:26.880 回答