List app for Freemark

Source: Internet
Author: User

Syntax:< #if ></#if > Background transfer list, the foreground HTML page gets the list and displays:

<#ifuserlist?exists>    <#listUserlistas Item>        <TR>          <TD>${ITEM_INDEX?IF_EXISTS+1}</TD>//Gets the loop subscript value, which is starting from 0 by default. <TD>${item.username?if_exists}</TD>        </TD>     </#list> </#if>

It is very convenient and most commonly used to display list contents in a template page:

1. If there is a bean class users,users has name, age and other properties,list<users> users as background data,

< #list users as user>
<span>${user.name}</span>
<span>${user.age}</span></br>
</#list >

2. The users section of the above example can also be defined in the field, as
< #list [1,2,3,4] as Index>
<span>${index}</span>
</#list >
The result is shown as: 1234

3. If you just want to count it, you can write it
< #list 1..4 as index>
<span>${index}</span>
</#list >
The result is the same as above, and it's 1234.

If you need to display the current loop to the first item, you can write this
< #list ["Hello", "Welcome", "HI"] as word>
<span>${word_index+1},${word}</span></br>
</#list >
The variable after the AS, plus _index, can represent the current loop to the first item
The result is:
1,hello
2,welcome
3,hi

Sometimes, the last item may have to be handled at the time of display, how to judge the last item?
< #list ["Hello", "Welcome", "HI"] as word>
<span>${word}</span>< #if word_has_next>,</#if ></#list >
As the variable behind the AS, plus _has_next, you can determine whether the last item
The result is:
Hello,welcome,hi

You can do this if you want to exit from a loop in which an item is determined
< #list users as user>
<span>${user.name}</span>
< #if User.Name = = "Pxx" >< #break ></#break >
</#list >

List app for Freemark

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.