New Content Iterators and More...

We recently added a few api enhancements for programatically working with content in Mura. With the new content iterators and new improved bean methods we were able to make managing content and users simpler. Here are some examples:

The New Content Iterator


<!--- Read out an existing node from the default site.---> 
<cfset content=application.contentManager.getActiveContentByFilename('blog','default')>

<!--- Pull out a content iterator of the nodes child content.--->
<cfset it=content.getKidsIterator()>

<!--- The number of Items to be listed is determined by the content.getNextN() value. It's default is 10. --->
<cfset it.setPage(1)>

<!--- You can also set the start row instead of setting a page number. --->
<cfset it.setStartRow(1)>
<cfloop from="1" to="#it.pageCount()#" index="p">
<cfset it.setPage(p)>
<cfoutput><h2>Page #p#</h2></cfoutput>
<!--- Iterate throught the child content.
The it.hasNext() will return true until the page length
as determined by the content.getNextN() has been reached --->
<cfloop condition="it.hasNext()"> <!--- The method returns a new contentNavBean. It acts as a facade to data into the wrapped query while digging into the full bean when needed. --->
</cfloop> </cfloop>


You can also get the same iterator from local content indexes:

<!--- Pull a index by it's name with the newfeedManager.readByName() method. This example is pulling alocal index named "documents" from the default site.---><cfset feed=application.feedManager.readByName('documents','default')><cfset it=feed.getIterator()><h2><cfoutput>#feed.getName()#</cfoutput></h2><cfif it.recordCount()><!--- Iterate throught the child content ---><cfloop condition="it.hasNext()"><cfset><cfoutput>#it.currentIndex()#: #subContent.getMenutitle()#</br></cfoutput></cfloop></cfif>
Wrap an Existing Query

You can also wrap any existing query that contains contentID and siteID or contentHistID and siteID and start iterating.

<cfquery name="rsExample">select content,siteID from tcontent where .....</cfquery><cfset it=application.serviceFactory.getBean("contentIterator")><cfset it.setQuery(rsExample)/><!--- Now Iterate and pull attributes that aren't in the query ---><cfloop condition="it.hasNext()"><cfset><cfoutput>#it.currentIndex()#: #content.getMenutitle()# - #content.getCustomVar()#</br></cfoutput>
You Can Event Start with a List
<cfset it=application.serviceFactory.getBean("contentIterator")><cfset it.BuildQueryFromList("423AC11B-3DB8-49EF-B411A2FB008CAB1E,423AC11B-3DB8-49EF-B411A2FB008CABAS","default")><!--- Now Iterate ---><cfloop condition="it.hasNext()"><cfset><cfoutput>#it.currentIndex()#: #content.getMenutitle()# - #content.getCustomVar()#</br></cfoutput>

Simpler Way to Manage Beans

Many beans in Mura now have direct methods for saving and deleting content instead of having to always submitting to it's appropriate service manager.<!--- Get members[returnType] returns usersthat belong to this use.For example if this user.getType() equas 1then it is a group and it would return it's members--->userBean.getMembersQuery()userBean.getMembersIterator()<!--- getMemberships[returnType] returns groups towhich this user belongs --->userBean.getMembershipsQuery()userBean.getMembershipsIterator()userBean.getAddressesQuery()userBean.getAddressesIterator()


Post a Comment

Required Field