質問

I'm using Velocity through a Java application. The velocity in question looks like this:

#if( $name1 != "" )
    #set($line11 = "<CharStyle:-bold black> ${name1}<CharStyle:>")
#end

And outputs as such:

$r<ParaStyle:-body copy>$line11

The output I see at the end of it all is:

${name1}

I want the value of name1 to be put into the stylization text, instead of the name of the variable. This seems to be how the Velocity specs tell me to do this. ( reference )What am I doing wrong?

役に立ちましたか?

解決

${name1} will evaluate to the literal string "${name1}" if name1 is null. So it looks to me like name1 is null. You might also want to change your #if condition to #if ($name1), which will evaluate to false if name1 is null.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top