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

228 views Asked by At

I would like to stop a loop in FreeMarker after 8 records are returned. 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>
1

There are 1 answers

0
Spanky On

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>