Reputation: 969
I get the following error when evaluating a velocity template.
Encountered "<EOF>" at <unknown template>[line 1, column 170]
Was expecting one of:
"[" ...
"(" ...
<RPAREN> ...
<ESCAPE_DIRECTIVE> ...
<SET_DIRECTIVE> ...
"##" ...
"\\\\" ...
"\\" ...
<TEXT> ...
"*#" ...
"*#" ...
"]]#" ...
<STRING_LITERAL> ...
<END> ...
<IF_DIRECTIVE> ...
<ELSEIF_DIRECTIVE> ...
<ELSE_DIRECTIVE> ...
<INTEGER_LITERAL> ...
<FLOATING_POINT_LITERAL> ...
<WORD> ...
<BRACKETED_WORD> ...
<IDENTIFIER> ...
<DOT> ...
"{" ...
"}" ...
<EMPTY_INDEX> ...
<DOT> ...
The template I am evaluating is this.
${fileName}_#if( $noticeType == 'typeA' )TypeAlpha#elseif( $noticeType == 'typeB' )TypeBeta#end_$date.format('yyyyMMdd', $myDate)
I need the whole string to be without spaces and to follow the format of fileName_TypeAlpha_20200423
, so my issue is with #end_
. The underscore is causing velocity to ignore the #end, so it cannot evaluate the if else statement.
How can I perform the #if #elseif #end and follow that immediately by an _
without spaces?
Thanks.
Upvotes: 2
Views: 5426
Reputation: 969
Found an answer.
I need to wrap the end in curly brackets to distinguish it from the rest of the text.
#{end}_
So my template is
${fileName}_#if( $noticeType == 'typeA' )TypeAlpha#elseif( $noticeType == 'typeB' )TypeBeta#{end}_$date.format('yyyyMMdd', $myDate)
See the very end of http://people.apache.org/~henning/velocity/html/ch05s03.html
Upvotes: 3