velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Reck <Christoph.R...@dlr.de>
Subject Re: Velocity
Date Thu, 29 Nov 2001 08:19:57 GMT
Hi Pavlo,

you can grab into the string trick box (as needed many times in JavaScript),
use:

#set( $list = ["1","12","123","1234"] )
#set( $spaces = "      " )

    First        Second
#foreach( $l in $list )#set( $fill = $spaces.substring( $l.length() ) )##
    $l$fill $fill$l
#end


Hope this helps. 


I use a similar trick to get zero-padded fixed length numbers:
#macro( fourdigit $num )
#set( $str = "$num" )
#set( $len = $str.length )
#set( $pad = "0000" )
#if( $len >= 4 )$str#else$pad.substring($len)$str#end##EOLescaped
#end

Another trick to get nicely formatted comma separated lists is:
#macro( csv $list )
#set( $sep = "" )
#foreach( $item in $list )
$sep$item##EOLescaped
#set( $sep = ", " )
#end
#end

:) Christoph


Pavlo Babachanakh wrote:
> To: <leon@opticode.co.za>
> Sent: Wednesday, November 28, 2001 2:52 PM
> Subject: Velocity
> 
> > Dear Leon!!
> >
> > I have tried to use Velocity Template Engine (version 1.2 rc3).
> > It's wonderful. But I have a problem and I don't
> > understand how to resolve it. I will try to explain it with an
> > example. I wanted to print some text in 2 columns. For this I
> > wrote the following template:
> >
> > #set( $list = ["1","12","123","1234"] )
> >
> >     First        Second
> > #foreach( $l in $list)
> >     $l           $l
> > #end
> >
> >
> > I got the following output:
> >
> >     First        Second
> >     1           1
> >     12           12
> >     123           123
> >     1234           1234
> >
> > But I want a different output:
> >
> >     First        Second
> >     1            1
> >     12          12
> >     123        123
> >     1234      1234
> >
> > How I can get the output I want?
> >
> > Thank you for your time.
> >
> > Sincerely,
> > Pavel Babachanakh
> > paul@uib.cherkassy.net
> >
> >
> 
> --
> To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>

--
To unsubscribe, e-mail:   <mailto:velocity-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:velocity-user-help@jakarta.apache.org>


Mime
View raw message