velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Leon Messerschmidt" <l...@opticode.net>
Subject Re: Velocity
Date Wed, 28 Nov 2001 14:05:46 GMT
Hi Pavlo,

Here are some suggestions - it is also a good idea to try the mailing list
if these don't help.

Option 1:

If you're working with html it is probably the easiest to use a table:

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

<table>
<tr>
  <td>First</td>
  <td>Second</td>
</tr>
#foreach( $l in $list)
<td>$l</td>
<td>$l</td>
#end
</table>

If you are not working with html one of the following options can probably
help you.

Option 2:

I haven't tried this myself, but you might be able to determine the
whitespace with a range operator and a foreach.  (See the user manual for
more information on the range operator).

Option 3:
You can add a tool to the context that does "pretty printing".  Something
like

public class PrettyPrinter
{
    public String makePretty (String one, String two, int stop)
    {
          StringBuffer sb = new StringBuffer()
          sb.append (one);
          while (sb.length() < stop)
          {
                sb.append(" ");
          }
          sb.append (two);
          return sb.toString();
    }
}

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

$p.makePretty ("First","Second")
 #foreach( $l in $list)
    $p.makePretty ($l,$l)
 #end

Hope this helps.

~ Leon

----- Original Message -----
From: "Pavlo Babachanakh" <Paul@uib.cherkassy.net>
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>


Mime
View raw message