You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Ch...@dlr.de on 2002/08/30 09:57:40 UTC
Re: Is there any way to have velocity programmatically print a newlin
e?
You can use the poor-man's solution with macros:
#macro( NL )##leave the following empty line to emit the \n
#end
and then set your delimeter using the interpolated output:
#apply1 ($retval ["foo", "bar", "baz", "qux"] "$x" "#NL()" $x)
^^^^^
Or to avoid having to call the macro every time...:
#set( $NL = "#NL()" )
The alternative, as Geir already stated, is to use some character
encoding/decoding tool to programatically generate the NL
character, e.g.:
#set( $NL = $decode("%0a") )
--
:) Christoph Reck
Jason Weinstein wrote:
> Is there any way to have velocity programmatically print a newline? I want
> to be able to inject newlines (see below).
>
> Example:
>
> #macro (apply1 $retval $list $pattern $delim $x)
> #set ($temp = "")
> ##
> #foreach ($elem in $list)
> #set ($x = $elem)
> #set ($temp = "$temp$pattern")
> #set ($temp = "$temp$delim")
> #end
> ##
> #set ($retval = $temp)
> #end
>
> #apply1 ($retval ["foo", "bar", "baz", "qux"] "$x" "\n" $x)
> $retval
>
> Get:
> foo\nbar\nbaz\nqux\n
>
> Want:
> foo
> bar
> baz
> qux
>
--
:) Christoph Reck
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>