Mura Content Types - Mura Docs v7.1

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}/themes/{ThemeName}/content_types/
  • {context}/sites/{SiteID}/themes/{ThemeName}/content_types/
  • {context}/sites/{SiteID}/content_types/
  • ../content_types/{type}/content_types/
  • ../content_types/{type}_{subtype}/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.
/modules/ Optional You may also include custom modules. This is useful for keeping modules and/or display objects directly related to specific content types together, in a unified directory structure. See Modules section for more information. See below for information on how to output modules in your layout template.
/content_types/ Optional You may include a nested "content_types" directory. This is a great way to keep related code items together.

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.renderEditableAttribute(attribute='body', type='htmlEditor')#
    </div>
  </article>
</cfoutput>

How To Output Modules

To output a module (display object) in your custom body layout, use the following syntax:

<cfoutput>
  #m.dspObject(object='{objectName}')#
</cfoutput>

When hardcoding a module in your layout, the "Delete" button will not appear for content managers when using the "Inline Edit" mode.

Including Configurable Modules

The first thing to understand about including configurable modules in your custom body layout is there can only be one (1) module that is configurable. Whichever module 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 modules using the code example above, the first module will be configurable, and all others will not. This means, when you select "Inline Edit" mode, only the first configurable module will include the pencil icon and actually be configurable.

To include additional modules, 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 module.