Customizing Default Output

Recently in the forum someone asked how they could change the default portal output for their news section.  I thought I should post my response here to highlight some important information about how to customize Standard Mura output without editing the main display files. This allows developers to upgrade their Mura instances without needin their customizations as well as opens the door for more structured content as well.

There are three ways to change a portals rendering with out touching the main code.

Global Resest

The first way can be done for any display object file in your site's  /[siteid]/includes/display_objects/. If you want to customize the rendering for all portals you can do a global reset by copying:

/[siteid]/includes/display_objects/dsp_portal.cfm

to

/[siteid]/includes/display_objects/custom/dsp_portal.cfm

and changing it.

Targeting a Sub Type with an Include

With the second way you can create files that only target a specific type and subtype. First you will need extend the base "Portal" type in your site's class extension manager by creating a subtype named "News" .

Next you need to copy

/[siteid]/includes/display_objects/dsp_portal.cfm

To

/[siteid]/includes/display_objects/custom/extensions/dsp_Portal_News.cfm

There you will be able to redefine the markup.  Notice the the naming convention for the file.

dsp_[Type]_[SubType].cfm

Using the Local EventHandler.cfc

Finally, the way we tend do it is by creating the same class extensions as in step two but using the local eventHandler.cfc (/[siteid]/includes/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

The methods can directory output the content or return a string.

<!---Direct output--->
<cffunction name="onPortalNewsBodyRender" output="true" returntype="void">
<cfargument name="event">
<cfset var content=event.getContentBean()>
<cfoutput>
<!--- The setDynamicContent() method is what executes the [mura] tag --->
#event.getContentRenderer().setDynamicContent(content.getBody())#
<!---You can create structured out put with Custom attribute--->
#content.getValue('customVar')#
</cfoutput>
</cffunction>
<!--- Returns a String--->
<cffunction name="onPortalNewsBodyRender" output="false" returntype="String">
<cfargument name="event">
<cfreturn event.getContentRenderer().setDynamicContent(event.getContentBean().getBody()) />
</cffunction>

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

Anyway, I thought this info might be of use to some people. Please feel free to post your thoughts.

Comments

Nathan Miller

This is great - however, when I implemented this with the subtype approach, my portal/child-page content shows, but not the main content defined on the page (i.e. the main body text usually displayed via request.contentBean.getbody()) - I can manually add this into the dsp file, but it seems like it should work automatically...I'm using version 5.0

November 2, 2009, 11:42 PM
Matt Levine

@Nathan

The main point of creating custom output for the body of a [Type]/[SubType] is to replace and not adjust the default output.

November 18, 2009, 3:12 PM
Nathan Miller

Ok, my thought for the implementation was like so: Say I'm using a portal for a product catalog and I want products displayed with a certain layout. I'm also using a portal for an FAQ section, which I want rendered in a different way. Is the SubType the way to go for this, or is there a better way?

November 18, 2009, 3:16 PM
Matt Levine

Yes, you would create two subtypes for Portals (Product and FAQ).

November 30, 2009, 6:46 PM
David

Got it to work matt! Thanks for your help! One question though: if i use the eventHandler as a means to display the extended attributes, will it get overwritten when i update the core files?

Thanks again,

David

January 20, 2010, 6:19 PM
Matt Levine

Awesome! Thanks for your patience with me trying to explain it.

January 20, 2010, 6:25 PM
David

One more question actually. If i'm using a value in an extended attribute that is pulling its content from another subType's extended attribute (for this example a school that must have a district that it belongs to), how do i show the value of the District name rather than the District ID?

Thanks again,

David

January 20, 2010, 6:34 PM
Matt Levine

You would need to read out that content:

<cfset district=application.contentManager.read(contentID=event.getContentBean().getValue("disctrictID"),siteID=event.getValue("siteID"))>

<cfoutput>

#disctrict.getTitle()#

</cfoutpuit

January 20, 2010, 6:56 PM
David

Got it!!

   <cfset districtBean=application.contentManager.getActiveContent(event.getContentBean().getValue('District'),event.getValue('siteid')) />

<strong>District:</strong> #districtBean.getTitle()#

is this the correct way of doing it? Also, will the root eventHandler get overwritten if i update the core files?

January 20, 2010, 7:02 PM
Matt Levine

That way is fine. Also, your evenHandler.cfc will not be overwritten in an auto update.

January 20, 2010, 7:20 PM
Post a Comment
  1. Leave this field empty

Required Field