CF Coding Practices
  • General Coding Practices
  • Debugging JSON-based CFC Methods
    • Valid JSON Formatting
    • Validating JSON
    • Final Hints
  • How We Invoke Modals
  • Submit Handlers
  • Useful SQL Snippets
  • jQuery/JS How-Tos And Hints
  • jQuery dataTables Tricks
  • CFSCRIPT Snippets and Hints
  • StatusPage Integration
  • Windows Server Setup
  • Common CF Formatting Commands
  • CF Snippets & Hints
  • Developing With The Mura Platform
    • ContentRenderer.CFC
    • Iterators
    • Iterating Remote Feeds
    • Components
    • Nested Content and Interactive Page Assembly
    • Modules and Display Objects
Powered by GitBook
On this page
  • Iterators
  • Content Iterator for Current Page
  • Content Feed Iterators

Was this helpful?

  1. Developing With The Mura Platform

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:

<cfset children = $.content().getKidsIterator()/>

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:

<cfset content = $.getBean('content').loadBy(contentID=$.content().getValue('ContentID'))/>
<cfset content.get('searchexclude','1')>
<cfset tabs = content.getKidsIterator()>

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:

<cfset feed=$.getBean('feed').loadBy(name="Products")> 
<cfset iterator=feed.getIterator()>
<cfif iterator.hasNext()>
<div> [display some stuff]</div>
<div>
<cfloop condition="iterator.hasNext()">
    <cfset content = iterator.next()/>
    <img alt="image" class="background-image" src="#$.createHREFForImage(fileid = content.getValue('ProductLogo'),size='logo')#" />
    <p>#content.getValue('title')#</p>
    <p>#content.getValue('TagLine1')#</p>
    <p>#content.getValue('TagLine2')#</p>
</cfloop>
</div>

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.

Remember that $.content().getValue() will retrieve information related to the current page and if you define an object that is loaded with a field (e.g. object = feed.iterator), then getValue() can be called on the object to get values from the feed once you point to which record in the feed you want by using the helper methods like .next().

PreviousContentRenderer.CFCNextIterating Remote Feeds

Last updated 6 years ago

Was this helpful?