freemarker取list的第一个元素 循环用法

 

freemarker取list的第一个元素 循环用法

<#list categories as c>
    <#list c.getForums() as f>
     <#if f_index == 0>
      <#assign default_forum_id = "${f.id}" />
     </#if>
    </#list>
</#list>

<div class="forumNameTags" id="forumNameTags">
${I18n.getMessage("ForumIndex.forumNameTags")}
<#assign n = 0 />
   
<#list categories as category>
   <#list category.getForums() as forum>
     <#assign n = n+1 /> 
     <#if n gt 5><#break></#if>//取前五条记录
     <a href="${JForumContext.encodeURL("/forums/show/${forum.id}")}">${forum.name?html}</a>&nbsp;&nbsp;  
   </#list>
   <#if n gt 5>//在五条记录后面加上一条更多的标签
    <span onclick="showMoreTags('forumNameMoreTags',event,-250,135);"><a href="#this" >${I18n.getMessage("ForumIndex.forumNameTagsMore")}</a></span>
    <#break>
   </#if> 
</#list>
</div>

<div id="forumNameMoreTags" class="popWindow" style="left:0px;top:0px;display:none;">
<div onclick="hiddenMoreTags('forumNameMoreTags')" class="popWindowTitle">x&nbsp;&nbsp;</div> 
<div class="padding">
<#assign n = 0 />
<#list categories as category>
   <#list category.getForums() as forum>
     <#assign n = n+1 />
     <a href="${JForumContext.encodeURL("/forums/show/${forum.id}")}">${forum.name?html}</a>&nbsp;&nbsp; 
     <#if n gt 2><br/><#assign n = 0 /></#if> //取三条记录
   </#list>
</#list>
</div>
</div>

===============

生成html

===============

<div id="forumNameTags" class="forumNameTags">
热门标签:
   
     <a href="/apollo/forums/show/1.page">股票大家谈</a>    
     <a href="/apollo/forums/show/2.page">行业公司研究</a>    
     <a href="/apollo/forums/show/3.page">投资交易策略</a>    
     <a href="/apollo/forums/show/4.page">创新产业研究</a>    
     <a href="/apollo/forums/show/5.page">社区资源下载</a>    
    <span onclick="showMoreTags('forumNameMoreTags',event,-250,135);"><a href="#this">更多...</a></span>
</div>
<div style="left: 0px; top: 0px; display: none;" class="popWindow" id="forumNameMoreTags">
<div class="popWindowTitle" onclick="hiddenMoreTags('forumNameMoreTags')">x   </div> 
<div class="padding">
     <a href="/apollo/forums/show/1.page">股票大家谈</a>   
     
     <a href="/apollo/forums/show/2.page">行业公司研究</a>   
     
     <a href="/apollo/forums/show/3.page">投资交易策略</a>   
     <br/> 
     <a href="/apollo/forums/show/4.page">创新产业研究</a>   
     
     <a href="/apollo/forums/show/5.page">社区资源下载</a>   
     
     <a href="/apollo/forums/show/7.page">上海个股</a>   
     <br/> 
     <a href="/apollo/forums/show/6.page">深圳个股</a>   
     
     <a href="/apollo/forums/show/8.page">红岭公告区</a>   
     
     <a href="/apollo/forums/show/9.page">社区事务处理</a>   
     <br/> 
     <a href="/apollo/forums/show/10.page">金牌分析师</a>   
     
</div>
</div>

你可能感兴趣的:(freemarker)