Skip to content

Instantly share code, notes, and snippets.

@JonasEriksson
Created April 18, 2016 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JonasEriksson/e49d99e39cd0cdc79cce4f8d52157a1a to your computer and use it in GitHub Desktop.
Save JonasEriksson/e49d99e39cd0cdc79cce4f8d52157a1a to your computer and use it in GitHub Desktop.
Mura CMS: Loading and displaying Mura Content Beans in a template
<!---
When building a single-page website with many content sections,
it can be easier to manage for end-users if the content parts
are managed as normal "pages" in Mura CMS, even if they are not
part of the normal/public site structure and/or navigation.
These normal content items (usually pages), then have Title,
Summary, Body, Associated Image etc. loaded by their respective
ContentID, page-name or titles.
The same applies to listing users with available contact information.
Below are a few examples on how this can be done for content.
--->
<!--- get a fresh bean --->
<cfset contentA = event.getBean( "Content" ) />
<!--- load it from the database based on the contentID --->
<cfset contentA.loadBy( contentID:"9829ED33-0F19-280D-8E1A95B2AD8D798D" ) />
<!--- Alternatively --->
<!--- load it from the database based on the contentTitle --->
<cfset contentA.loadBy( contentID:"myContentTitle" ) />
<!--- Alternatively --->
<!--- load it from the database based on the fileName --->
<!--- Note1: You see the Current Filename on the Advanced tab in Site Manager -> Edit Content --->
<!--- Note2: You can also simply read it of the URL, it is the part after "index.cfm/" and minus the trailing "/" --->
<cfset contentA.loadBy( fileName:"ExamplePage1/ExampleSubPage2" ) />
<!--- display the datafields in the template --->
<cfoutput>Title: #contentA.getTitle()#</cfoutput><br>
<cfoutput>Summary: #contentA.getSummary()#</cfoutput><br>
<cfoutput>Body: #contentA.getBody()#</cfoutput><br>
<cfoutput>Credits: #contentA.getCredits()#</cfoutput><br>
<cfoutput>Associated Image (show URL only): #contentA.getImageURL()#</cfoutput><br>
<cfoutput>Associated Image (display the image): <img src="#contentA.getImageURL()#" alt="#contentA.getTitle()#"></cfoutput><br>
<!--- Note3: To display an extended attribute, simply do this: --->
<cfoutput>ExtendedAttribute: #contentA.getYourExtendedAttributeName()#</cfoutput><br>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment