Mura Iterators - Mura Docs v6

Mura Iterators

In short, an "iterator" is an array of objects. Mura iterators make managing content and users simpler by providing direct access to objects and their properties as well as offering a number of "helper" methods.

A Mura Iterator wraps a traditional CFML query object. It is most often used in conditional loop statements:

<cfloop condition="iterator.hasNext()">

And the first line inside of the condition loop is obtaining a reference to the actual next value object:

<cfset item = iterator.next() />

And you then can use it for whatever the purpose of the iteration is for:

#HTMLEditFormat(item.getValue('myVar'))#

It is very important to note that the the iterator.hasNext() is page aware. The Mura Iterator was built with pagination in mind. This means that iterator.hasNext() with only return true if it was iterated through less than the value of its iterator.getNextN() value.

For example, if an iterator has 20 items inside of it, the following code would output the first 10:

<cfset iterator.setNextN(10)>
<cfoutput>
<cfloop condition="Iterator.hasNext()">
<cfset item=Iterator.next()>
#HTMLEditFormat(item.getValue('myVar'))#
</cfloop>
</cfoutput>

If you set the value of the Iterator's nextN to 0 it will set next to the recordcount of the current query:

<cfset iterator.setNextN(0)>

You can change the page that is iterated through by settings the iterator's current page:

<cfset iterator.setPage(2)>

You can also iterate backwards as well:

<cfset iterator.end()>
<cfoutput>
<cfloop condition="iterator.hasPrevious()">
<cfset item=iterator.previous() />
#HTMLEditFormat(item.getValue('myVar'))#
</cfloop>
</cfoutput>