component - Mura Docs v7.0

component

A Mura Scope object, (also referred to as a "subscope" of the Mura Scope), that provides access to several helper methods for a Component Item in the current request context, as well as easy access to its attributes.

Function Syntax

m.component( property, propertyValue )

Parameters

Parameter Type Req/Opt Default Description
property string Opt  

Optionally pass in an attribute name, and Mura will return its value (unless a propertyValue is also provided). If the property parameter is omitted, Mura will return a content object, which has several helper methods associated to it. Mura "components" are really just "content objects" which is why it returns a "content object" and not a "component object."

propertyValue any Opt  

If you pass in a property, you may optionally "set" the value of the property by passing in a value to this parameter. If you leave this parameter empty, Mura will return the actual value stored in the database for the requested property.

Usage

Use this function to "get" and/or "set" values of the component item. The content/component object also has a number of helper methods, very useful for theme developers, and are noted below under the Examples.

Examples

Note: Some of the examples below make use of esapiEncode to encode a given string for safe output to stop Cross Site Scripting attacks.

Component Body

The following example outputs the "Body/Content" of the component item in the current request context.

<cfoutput>
<article>
#m.component('body')#
</article>
</cfoutput>

If you want Mura [m] Tags to render, you will want to wrap the output with m.setDynamicContent().

<cfoutput>
<article>
#m.setDynamicContent(m.component('body'))#
</article>
</cfoutput>

Component Title

The following example outputs the "Title" of the component item in the current request context.

<cfoutput>
<h2>
#esapiEncode('html', m.component('title'))#
</h2>
</cfoutput>

Date Created

This example outputs the date the content item was originally created on. For more information on the CFML tag DateFormat, please visit https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-functions/functions-c-d/DateFormat.html

<cfoutput>
<p>
Date Created: #DateFormat(m.component('created'), 'YYYY-MM-DD')#
</p>
</cfoutput>

Date Last Updated

This example outputs the date the component item was last updated.

<cfoutput>
<p>
Date Last Updated: #DateFormat(m.component('lastUpdate'), 'YYYY-MM-DD')#
</p>
</cfoutput>

Last Updated By

This example outputs the first and last name of the content manager who last updated the component item.

<cfoutput>
<h2>
Last Updated By: #esapiEncode('html', m.component('lastUpdateBy'))#
</h2>
</cfoutput>

Inspecting Available Attributes

This example demonstrates how to inspect the available attributes of a component item. For more information the CFML tag cfdump, please visit https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-d-e/cfdump.html.

<cfdump var="#m.component().getAllValues()#">