Targeting a SubType - Mura Docs v6

Targeting a SubType

Once you complete the "Class Extensions" section of this guide, this section will make a bit more sense. However, this approach allows you to create files that only target a specific Type and subType. You can modify the output of any base type in Mura (Page, Gallery, Folder, etc.).

In this example, we're going to modify the output of the Folder type. First, extend the base Folder type in your site's class extension manager by creating a SubType named News.

Next you copy:




Note the the naming convention for the file:


If this is something that you would like include in to a theme you can also add your custom file there:


Lookup Hierarchy

  1. /{SiteID}/includes/themes/{theme}/display_objects/custom/extensions/dsp_{Type}_{SubType}.cfm
  2. /{SiteID}/includes/themes/{theme}/display_objects/extensions/dsp_{Type}_{SubType}.cfm
  3. /{SiteID}/includes/display_objects/custom/extensions/dsp_{Type}_{SubType}.cfm

Using EventHandler.cfc

Another option is to create the same class extensions as in step two but use the Site eventHandler.cfc (/{siteID}/includes/eventHandler.cfc) or Theme eventHandler.cfc (/{SiteID}/includes/themes/{ThemeName}/eventHandler.cfc). There you can create a method that follows a specific naming convention that will trigger Mura to use it instead of the default code.

The naming conventions are:


Direct Output

public any function onPageBlogBodyRender($) {
// setDynamicContent() method is what parses
// and executes the [mura][/mura] tags
// You can create structured output with
// custom attributes
WriteOutput('Product Description: ');

Returning a String

public string function onPageBlogBodyRender($) {
return $.setDynamicContent($.content('body'));

The benefit of this approach is that you can later take this method and register it within a plugin if you want to redistribute it.

Using the Theme eventHandler.cfc

In the exact same way that you are able to register events in your site local eventHandler (/{SiteID}/includes/eventHandler.cfc), you are also able to distribute an eventHandler.cfc within themes (/{SiteID/includes/themes/{ThemeName}/eventHandler.cfc). The main difference between using the site's eventHandler.cfc and a theme's eventHandler.cfc is that a theme's eventHandler.cfc is only read in during the onApplicationLoad event and the Site eventHandler.cfc is instantiated on a per request basis. Therefore, anytime you alter the theme's eventHandler.cfc, you need to reload the application for the changes to be registered.

Model-View-Controller (MVC)

You are free to work with whichever method(s) you find most useful to you as a developer. However, it may be helpful to use the Site and Theme eventHandlers as "controllers" in a Model-View-Controller (MVC) application. Using this concept, the dsp_{Type}_{Subtype}.cfm files could then be utilized as the "view" in an MVC application. By segregating these duties, this will allow for front-end developers and/or designers to work within the "view" and abstract business logic that may simply confuse them or get in their way.