Mura Content Types
In addition to using some of Mura's content-related event hooks, developers can control the rendering of the body area by targeting a content's Type
and Subtype
. This feature also applies to any custom Class Extensions. For example, "Folder/Contacts", "Page/Contact", etc.
Mura automatically scans the following directories for custom content types:
{context}/{SiteID}/includes/themes/{ThemeName}/content_types/
{context}/{SiteID}/includes/content_types/
Or, you can register any directory you want by using the following syntax:
m.siteConfig().registerContentTypeDir( '/path/to/your/content_types/' ); // Path is a logical path to a CFML directory // Usually registered in onApplicationLoad();
Note: This feature only works if the layout template is using m.dspBody() to render the body area.
Control Body By Type/Subtype
You target the body's Type/Subtype
by a conventional directory structure.
For example, you could target content by only its Type:
../content_types/{type}/ // If you wish to target 'Page' ../content_types/page/index.cfm
Or, you can target by both the Type, and its Subtype:
../content_types/{type}_{subtype}/ // If you wish to target 'Page/Contact' ../content_types/page_contact/index.cfm
Anatomy of a {type}_{subtype} Directory
As previously mentioned, you create a directory under a known or registered "content_types
" directory by using {type}_{subtype}
(e.g., ../content_types/page_contact/
or ../.content_types/component_default/
, etc.). Within the {type}_{subtype}
directory, you may have the following files and/or directories:
File or Directory | Req/Opt | Description |
---|---|---|
index.cfm | Required | This is the body or view used by Mura for display file itself. At a minimum, this file should contain <cfoutput>#m.renderEditableAttribute(attribute="body",type="htmlEditor")#</cfoutput> , if you wish to see any text entered into the "Content" area. See example "index.cfm" file below. |
config.xml.cfm | Optional | This is the configuration file. This allows you to include custom image sizes, class extensions, and more. See Elements Of the "config.xml.cfm" File section for more information. |
/model/ | Optional | If you wish to leverage Mura ORM, the content type could have its own "model " directory, which in turn could also include a "beans " and/or "handlers " directory too. See Mura ORM Configuration section for more information about the "model" directory. |
/display_objects/ | Optional | You may also include custom display objects. This is useful for keeping display objects directly related to specific content types together, in a unified directory structure. See Display Objects section for more information. See below for information on how to output display objects in your layout template. |
Example "index.cfm" File
The example below illustrates what an "index.cfm
" file could contain. However, you may include your own custom markup, code, and more.
<cfoutput> <article class="article"> <!--- Page Title ---> <h2 class="article__title">#m.renderEditableAttribute(attribute='title')#</h2> <!--- Primary Image ---> <cfif m.content().hasImage(usePlaceholder=false)> <figure class="article__image"> <img src="#m.getURLForImage(fileid=m.content('fileid'), size='medium')#" alt="#esapiEncode('html_attr', m.content('title')#" /> </figure> </cfif> <!--- Content ---> <div class="article__body"> #m.renderEditablerAttribute(attribute='body', type='htmlEditor')# </div> </article> </cfoutput>
How To Output Display Objects
To output a display object in your custom body layout, use the following syntax:
<cfoutput> #m.dspObject(object='{objectName}')# </cfoutput>
When hardcoding a display object in your layout, the "Delete" button will not appear for content managers when using the "Inline Edit" mode.
Including Configurable Display Objects
The first thing to understand about including configurable display objects in your custom body layout is there can only be one (1) display object that is configurable. Whichever display object you wish to be configurable should include a "objectparams
" parameter, and include the "objectparams
" as the value, as shown below:
<cfoutput> #m.dspObject(object='{objectName}', objectparams=objectparams)# </cfoutput>
If you attempt to include multiple configurable display objects using the code example above, the first display object will be configurable, and all others will not. This means, when you select "Inline Edit" mode, only the first configurable display object will include the pencil icon and actually be configurable.
To include additional display objects, you may pass in any "objectparams
" parameters as an object, as show in the example below:
<cfoutput> #m.dspObject( object='object1', objectparams={param1=objectparams.param1, param2=objectparams.param2} )# #m.dspObject(object='object2', objectparams=objectparams)# </cfoutput>
In the example above, "object2
" will be the only configurable display object.