Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"for" loop in velocity template

I already posted a similar question a week ago on How to use 'for' loop in velocity template?.

So...basically I can't use 'for' loop in a velocity template.

Let's say I have a variable that holds integer 4. I want to display something four times using that variable. How do I do it in a velocity template?

like image 316
Moon Avatar asked Apr 20 '11 18:04

Moon


People also ask

How do you write a Velocity template?

3.2 Create a Velocity Template Writer Initialize the Velocity engine. Read the template. Put the data model in a context object. Merge the template with context data and render the view.

What is a Velocity template?

Velocity is a server-side template language used by Confluence to render page content. Velocity allows Java objects to be called alongside standard HTML. If you are are writing a user macro or developing a plugin you may need to modify Velocity content.

How do I test a Velocity template?

Approach 1: The obvious approach: Run and check. Run Velocity against the template to be checked. Look at the output and see if it is what you desired. This must be the most primitive testing approach, but most people nowadays are too lazy and want this done by the computer.


1 Answers

Try to do it like this:

#set($start = 0) #set($end = 4) #set($range = [$start..$end]) #foreach($i in $range)    doSomething #end 

The code has not been tested, but it should work like this.

like image 137
csupnig Avatar answered Nov 14 '22 16:11

csupnig