Iterators
Iterators
Mura allows you to loop through Mura-managed content using content iterators - a built-in Mura module. Iterators can be used to retrieve content related to specific pages, folders, etc. by referencing the content ID, page title, etc.
Content Iterator for Current Page
Retrieving an iterator of content for children of the current page or folder is easy:
If you want to use filtering or parameters to adjust what children are returned in this scenario, you will need to use the long form of defining the iterator content:
In the above example, the children of the current page are retrieved, even if the are set to be excluded from the site search (normally, the getKidsIterator() excludes any children excluded from the site search).
Content Feed Iterators
Many times we are looping over content from a feed/collection that we've created in Mura. For example, we've created a content feed/collection for an area (folder with child pages) of the site called "products" and we now want to loop through the collection to populate an area of a page on the site with some information related to this feed:
In the above coding example, a reference to the feed is created as a new object by loading the feed based on the name of the feed/collection in the Mura admin. An iterator method is then called on the feed object. A cfif is then called to see if the feed has any content (if not, it doesn't attempt to display any related content). A loop is then called with the same condition. Inside of the loop, we create a pointer (structure) that addresses the current item in the feed (the cfloop will update this pointer, looping through all of the content in the feed). Once we have that pointer, we can refencing Mura pre-defined objects (page title, page body, etc.) as well as any custom fields/elements that we've added as attributes. In the above example, line #9 references a build-in Mura content element ("title") and lines #10 and #11 reference attributes ("TagLine1" and "TagLine2") that were added using the class extention feature in the Mura admin. Line #8 also retrieves a custom attribute (in this case an image) called ProductLogo.
Last updated
Was this helpful?