Displaying Extended Attributes - Mura Docs v7.0

Displaying Extended Attributes

There are a few ways to display the attributes of Class Extensions, and it really depends on where you're attempting to display them. That said, the most important thing to keep in mind is that you'll need to know your attribute's name property, in order to display it.

In short, a Class Extension's attribute is treated as a property of the bean it's associated with. So, for example, if a Class Extension's Base Type is Content, then you could use the same getter and setter methods when working with any other attribute of a Content Bean.

Basic Syntax

The basic syntax is shown in the example below.

someBean.get('attributeName')
someBean.get{AttributeName}()
someBean.getValue('attributeName')

Examples

The examples listed below demonstrate the most common method for accessing attributes of a Class Extension. In addition, the recommended best practice is to use esapiEncode when outputting attributes.

Via Layout Template

This example assumes the Base Type is "Content", and you merely want to display the attribute on a layout template.

<cfoutput>
<h2>
  #esapiEncode('html', m.content('attributeName'))#
</h2>
</cfoutput>

Via HTML Editor

This example assumes you wish to output an attribute in the body of a HTML Editor.

[m]esapiEncode('html', m.content('attributeName'))[/m]

Via Content Bean

This example assumes you load a Content Bean, and then want to retrieve the data for whatever reason.

contentBean = m.getBean('content').loadBy(title='Home');
// assumes we have a custom attribute labeled `locationstreet`
street = contentBean.get('locationstreet');

Via Iterator

You can easily pull out attributes of Class Extensions while looping inside of a Mura Iterator.

<!--- get an iterator of the content item's children --->
<cfset it = m.content().getKidsIterator()>
<ul>
<cfloop condition="it.hasNext()">
<cfset item = it.next()>
  <li>
  #esapiEncode('html', item.get('attributeName'))#
  </li>
</cfloop>
</ul>