turbine-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Baragry <Jason.Bara...@nr.no>
Subject Re: while loops in velocity templates
Date Fri, 27 Jun 2003 09:12:48 GMT
Henning P. Schmiedehausen wrote:
> Keith Seim <keith@kjsdesigns.com> writes:
> 
> Ask yourself if this is the scope of the templating language or a
> programming language. If you come up with "programming language", move
> the code to a pull tool as it was suggested by some others.
> 
> Velocity is a language to build templates from your internal data
> representation. If you need to embed a programming language in your
> templates, use PHP, Jython or JSPs. You have a fully fledged Java
> programming environment at your fingertips to write the functionality
> of your code. This is not the job of Velocity. :-)

I had a problem that required a while loop in the template and
not the code. I needed to add some blank columns in a table before
inserting the text in my list. (to make my table look a little
like a tabbed pane).

I got around it with the following velocity construct:

- headings is my list of columns in the table.
- column is the name of the heading I want to insert the radio box
  under.

         #foreach ($subH in $subHeadings)
         <tr>
             #if ($headings.indexOf($column) > 0)
                #foreach ($foo in [1..$headings.indexOf($column)])
                   <td></td>
                #end
             #end
             #formRadioBox ($subH "productType" "true")
          </tr>

If you search the velocity user guide and play around with the
foreach directive using the [1..N] parameter you can make
it work like a while loop.

cheers

Jason


---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-user-help@jakarta.apache.org


Mime
View raw message