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:
/{siteID}/includes/display_objects/dsp_folder.cfm
to
/{siteID}/includes/display_objects/custom/extensions/dsp_Folder_News.cfm
Note the the naming convention for the file:
dsp_{Type}_{SubType}.cfm
If this is something that you would like include in to a theme you can also add your custom file there:
/{siteID}/includes/themes/{theme}/display_objects/custom/extensions/dsp_{Type}_{SubType}.cfm
Lookup Hierarchy
- /{SiteID}/includes/themes/{theme}/display_objects/custom/extensions/dsp_{Type}_{SubType}.cfm
- /{SiteID}/includes/themes/{theme}/display_objects/extensions/dsp_{Type}_{SubType}.cfm
- /{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:
on[Type]BodyRender on[Type][SubType]BodyRender
Direct Output
public any function onPageBlogBodyRender($) { // setDynamicContent() method is what parses // and executes the [mura][/mura] tags WriteOutput($.setDynamicContent($.content('body'))); // You can create structured output with // custom attributes WriteOutput('Product Description: '); WriteOutput($.content('productDescription')); }
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.