简体   繁体   English

返回一定数量的记录后如何停止循环?

[英]How can I stop a loop after a certain amount of records are returned?

I would like to stop a loop in FreeMarker after 8 records are returned.我想在返回 8 条记录后停止 FreeMarker 中的循环。 So far, I have the following code到目前为止,我有以下代码

<#ftl ns_prefixes={"content":"http://purl.org/rss/1.0/modules/content/","dc":"http://purl.org/dc/elements/1.1/"}>
    <#list kiblogs.rss.channel.item as item>
        <div class="span4">
            <div class="panel">
                <img src="${item.thumbnail.@@nested_markup}" class="title-image"> 
                <div class="top-content">
                    <h3>${item.title}</h3>
                    <div class="datetime">${item.pubDate?substring(0, 16)}</div>
                    <div class="analyst">${item["dc:creator"]}</div>
                    <p class="ellipsis multiline">${item.description}</p>
                    <div class="bottom-blue-buttn">
                        <a class="launch" attrId="${item.uid}">Read the blog</a>
                    </div>                  
                </div>
            </div>
        </div> 
        <hr>            
</#list>

I solved it by adding我通过添加解决了它

<#if item_index==8><#break></#if>  

So my code is now所以我的代码现在是

<#ftl ns_prefixes={"content":"http://purl.org/rss/1.0/modules/content/","dc":"http://purl.org/dc/elements/1.1/"}>

      <#list kiblogs.rss.channel.item as item>
          <div class="span4">
            <div class="panel">
              <img src="${item.thumbnail.@@nested_markup}" class="title-image"> 
                <div class="top-content">
                  <h3>${item.title}</h3>
                  <div class="datetime">${item.pubDate?substring(0, 16)}</div>
                  <div class="analyst">${item["dc:creator"]}</div>
                  <p class="ellipsis multiline">${item.description}</p>
                  <div class="bottom-blue-buttn"><a class="launch" attrId="${item.uid}">Read the blog</a></div>                  
                </div>

            </div>
           </div> 

        <hr>
       <#if item_index==8><#break></#if>              
      </#list>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM