You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Jason Weinstein <JW...@SeeBeyond.com> on 2002/08/29 21:45:41 UTC
Is there any way to have velocity programmatically print a newlin
e?
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
Re: Is there any way to have velocity programmatically print a newlin
e?
Posted by Ch...@dlr.de.
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>
Re: Is there any way to have velocity programmatically print a newlin
e?
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 8/29/02 3:45 PM, "Jason Weinstein" <JW...@SeeBeyond.com> 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
>
It depends what the output is. HTML is generally newline agnostic. If
text, then you could put a "\n" from java in the context and use that, or a
character generating tool for more general use...
--
Geir Magnusson Jr.
Research & Development, Adeptra Inc.
geirm@adeptra.com
+1-203-247-1713
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>