You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Pavel Babachanakh <Pa...@uib.cherkassy.net> on 2001/11/29 10:37:02 UTC
Align
Hi Christoph,
Thank you for your quick response. It works. But where can I read about such
functions as substring() and length() and others? I didn't find them in
docs.
Pavel
----- Original Message -----
From: "Christoph Reck" <Ch...@dlr.de>
To: "Velocity Users List" <ve...@jakarta.apache.org>; "Pavlo
Babachanakh" <Pa...@uib.cherkassy.net>
Sent: Thursday, November 29, 2001 10:19 AM
Subject: Re: Velocity
> 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: <le...@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:
<ma...@jakarta.apache.org>
> > For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Align
Posted by "Geir Magnusson Jr." <ge...@optonline.net>.
On 11/29/01 4:37 AM, "Pavel Babachanakh" <Pa...@uib.cherkassy.net> wrote:
> Hi Christoph,
>
> Thank you for your quick response. It works. But where can I read about such
> functions as substring() and length() and others? I didn't find them in
> docs.
They wouldn't be in the Vleocity docs... It would be the API docs....
$spaces is a java.lang.String, so you can use any public method of that
class.
geir
>
> Pavel
>
>
> ----- Original Message -----
> From: "Christoph Reck" <Ch...@dlr.de>
> To: "Velocity Users List" <ve...@jakarta.apache.org>; "Pavlo
> Babachanakh" <Pa...@uib.cherkassy.net>
> Sent: Thursday, November 29, 2001 10:19 AM
> Subject: Re: Velocity
>
>
>> 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: <le...@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:
> <ma...@jakarta.apache.org>
>>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>>
>> --
>> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
>> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
--
Geir Magnusson Jr. geirm@optonline.net
System and Software Consulting
You're going to end up getting pissed at your software
anyway, so you might as well not pay for it. Try Open Source.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>