content
A Mura Scope object, (also referred to as a "subscope" of the Mura Scope), that provides access to several helper methods for the Content Item in the current request context, as well as easy access to its attributes.
Function Syntax
m.content( 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 | any | Opt |
If you pass in a |
Usage
Use this function to "get" and/or "set" values of the content item. The content 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.
Content Title
The following example outputs the "Title" of the content item in the current request context.
<cfoutput> <h2> #esapiEncode('html', m.content('title'))# </h2> </cfoutput>
HTML (Browser) Title
The following example outputs the "HTML (Browser) Title" of the content item in the current request context.
<cfoutput> <title> #esapiEncode('html', m.content('HTMLTitle'))# </title> </cfoutput>
You could also combine this with the siteConfig's "Site Name" attribute, to have a full <title>
for your theme's layout template.
<cfoutput> <title> #esapiEncode('html', m.content('HTMLTitle'))# - #esapiEncode('html', m.siteConfig('site'))# </title> </cfoutput>
Content Summary
The following example outputs the "Summary" of the content item in the current request context.
<cfoutput> <article> #m.content('summary')# </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.content('summary'))# </article> </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.content('created'), 'YYYY-MM-DD')# </p> </cfoutput>
Date Last Updated
This example outputs the date the content item was last updated.
<cfoutput> <p> Date Last Updated: #DateFormat(m.content('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 content item.
<cfoutput> <h2> Last Updated By: #esapiEncode('html', m.content('lastUpdateBy'))# </h2> </cfoutput>
Credits (Author)
This example outputs the "Credits" attribute (from the Publishing tab).
<cfoutput> <h2> Author/Credits: #esapiEncode('html', m.content('credits'))# </h2> </cfoutput>
Meta Description
This example shows how to output text entered into the Meta Description field.
<cfoutput> <meta name="description" content="#esapiEncode('html_attr', m.content('metaDesc'))#"> </cfoutput>
Meta Keywords
This example shows how to output text entered into the Meta Keywords field.
<cfoutput> <meta name="keywords" content="#esapiEncode('html_attr', m.content('metaKeywords'))#"> </cfoutput>
Get Associated Image
This example shows how to output the primary associated image of a content item. It uses a simple bit of CFML logic first, to make sure an image actually exists. For more information on the CFML tag cfif, please visit https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-i/cfif.html
<cfoutput> <cfif Len(m.content().getImageURL('medium'))> <img src="#m.content().getImageURL('medium')#"> </cfif> </cfoutput>
Inspecting Available Attributes
This example demonstrates how to inspect the available attributes of a content 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.content().getAllValues()#">