Search code examples
loopscoldfusionmura

Coldfusion loop in mura stop after 10 iterations


Can anyone see what is wrong with this loop? I am not a coldfusion developer but I am doing something for our absent developer. I am trying to get the loop to stop after 10 iterations but it is not happening. The CMS I am using is Mura. Thanks.

                    <cfset limit = 1>
                    <cfloop condition="iterator.hasNext()">
                        <cfif limit LTE 10>
                        <cfoutput>
                            <cfset item = iterator.next()>
                                <tr>
                                    <td>#item.getId()#</td>
                                    <td>#item.getTitle()#</td>
                                </tr>
                         </cfoutput>    
                         </cfif>
                        <cfset limit = limit + 1>
                    </cfloop>

Solution

  • While Ben's answer will work, the best option is to tell the Mura iterator how many iterations to do before beginning the loop.

    <cfset iterator.setNextN(10) />
    <cfloop condition="iterator.hasNext()">
        <cfset item = iterator.next()>
            <cfoutput>
                <tr>
                    <td>#item.getId()#</td>
                    <td>#item.getTitle()#</td>
                </tr>
            </cfoutput>    
    </cfloop>
    

    Typically it defaults to 10, so somewhere in your settings or code it must be set to more.