FreeMarker grammer

1. Map

Render the values of a Map

The following code snippet shows how to get the values of a Map (e.g. HashMap) from within a Freemarker template.

<#assign m = myMap>
<#assign values = m?values>
         
<ul>
     <#list values as myObject>
     <li>${myObject.myPropery}</li>
     </#list>
</ul>
 
Render the keys of a Map

You can do a similar thing with the keys of a map as shown below.

<#assign m = myMap>
<#assign keys = m?keys>
         
<ul>
     <#list keys as key>
     <li>${key}</li>
     </#list>
</ul>
 
 

<#foreach friendId in entry.commonFriends>
//friendId 是int类型
<#if results.commonFriendsProfileMap[friendId?string]??>

//friendId?string 将int转为string类型,commonFriendsProfileMap的value值为一个对象
${results.commonFriendsProfileMap[friendId?string].name}
${results.commonFriendsProfileMap[friendId?string].photoUrl}
</#if>
</#foreach>

 
2.list
 

<#assign pageStart=results.listPageStart>
<#assign pageEnd=results.listPageEnd>
<#list pageStart..pageEnd as index>
<#if results.currentPage == index>
${index}
</#if>
</#if>
</#list>

 

<#list entry.object.skills as skill>
<#if skill_index &lt; 3 >
//list里是对象,只在list里取三个
${skill.skill_name} |${skill.skill_level}

</#if>
</#list>

3. if else 
 

<#if entry.count &gt; 1000>
<#elseif entry.count ==2>

<#else>

</#if>

posted on 2013-07-31 11:40  ukouryou  阅读(181)  评论(0编辑  收藏  举报

导航