I want to create for statement in freemarker template. I am reading howto http://freemarker.sourceforge.net/ but there is just list. How can i create for statement or foreach.
parameter.put("size", size);
I want to create in freemarker template for statement like
for (int number = 1; number <= size; number++) {
From the Freemarker manual you can do:
<#assign x=3>
<#list 1..x as i>
${i}
</#list>
Edit: Beware, if x
is 0 (or less), it will count backwards. So you mostly want 1 ..< x
, which excludes x
(this requires FreeMarker 2.3.22).
You can use list
directive:
<ul>
<#list 1..2 as index>
<li>${index}</li>
</#list>
</ul>
Here size=2
<#list 0..2 as x>
<#if x gt 0>
${x}
</#if>
</#list>
output:
1
2
It will not print anything if size is zero.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.