Blog

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]BodyRenderon[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, 3:42 PM
Reply
Flag as Spam
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, 7:12 AM
Reply
Flag as Spam
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, 7:16 AM
Reply
Flag as Spam
Matt Levine

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

November 30, 2009, 10:46 AM
Reply
Flag as Spam
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, 10:19 AM
Reply
Flag as Spam
Matt Levine

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

January 20, 2010, 10:25 AM
Reply
Flag as Spam
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, 10:34 AM
Reply
Flag as Spam
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, 10:56 AM
Reply
Flag as Spam
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, 11:02 AM
Reply
Flag as Spam
Matt Levine

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

January 20, 2010, 11:20 AM
Reply
Flag as Spam
Paul Richardson

I have tried this, but just can't get it to work.

Trying to create a page sub-type that will output Local Content Index in a different way (as a list I can style to output horizontally, instead of as a vertical dl list).

I created the dsp_feed_sponsor.cfm template under the custom\extension directory and modified the template.

I edited the eventHandler.cfc file to include the first (direct output) cffunction.

I added the class extension for Page: Sponsor.

Reassigning the test page to type of Page/Sponsor in Site Manager.

But the page still outputs using the old dsp_feed.cfm file.

What's up? Did I miss a step?

PR

November 3, 2010, 9:12 AM
Reply
Flag as Spam
Paul Richardson

Got it.

Got it to to work with dsp_portal file, but is there a way to do this to customize feed output? Feed is not a "base" type like Portal, so how does one go about having the ability to have alternative feed output styles, defined by which Component is selected?

PR

November 7, 2010, 6:30 AM
Reply
Flag as Spam
Boon

Hi there

I have had a bit of fun seeing if I could get it to work.

As I understand it,

1. if you add nothing to eventhandler.cfc, then "dsp_[Type]_[SubType].cfm" is called, and rendered with the magic code: "[mura ]$ .dspBody(body=$ .content('body'),pageTitle='',crumbList=0,showMetaImage=0) [/mura ]";

2. if you use the "[!---Direct output---] method, then

"dsp_[Type]_[SubType].cfm" is not called. Makes sense, as the code placed in eventhandler.cfc is executed instead.

3. With the code below the comment [!--- Returns a String---] in the original post, I inserted some plain text in the dsp_Portal_[SubType].cfm. I was expecting the string which I placed in that file to be returned, but it was not.

What am I missing with this third method?

Boon

September 30, 2012, 10:56 AM
Reply
Flag as Spam
Post a Comment

Required Field