Installation Wide contentRenderer for MuraCMS
I have a fairly large Mura installation, with a good number of sites on it. I have some customizations that I’d like to be pushed out across all of the sites in my installation. For example, I’ve changed the way the dspPrimaryNav function works, so that I can prevent child pages from being displayed. Unfortunately, as flexible and customizable as Mura is, there is no good to make global changes to the contentRenderer.cfc without losing those changes everytime you perform an update to your core files.
To make this happen, we’re going to use the flexibility of extending components to create a custom contentRenderer.cfc that all sites in our installation will use. So first, we’ll create a directory at the root of our Mura installation called custom. In here we’re going to place all global custom functions we want to override. Here’s mine:
<cfcomponent extends="mura.content.contentRenderer">
<cfset this.jslib="jquery"/>
<cfset this.jsLibLoaded=true>
<cfset this.headline="h1"/>
<cfset this.subHead1="h2"/>
<cfset this.subHead2="h3"/>
<cfset this.subHead3="h4"/>
<cfset this.subHead4="h5"/>
<!--- Adjusted to nav to add the ability to prevent all children from being displayed --->
<cffunction name="dspNestedNavPrimary" output="false" returntype="string">
... a bunch of custom code here ...
</cffunction>
<cffunction name="dspPrimaryNav" returntype="string" access="public">
... a bunch of custom code here ...
</cffunction>
</cfcomponent>
Don’t worry about the two functions. The only really juicy bit there is the extends="mura.content.contentRenderer", which is the way Mura suggests you implement your own custom contentRenderer.cfc. So now that that’s complete, let’s go into our site folder at oursite/includes/ and open the contentRenderer.cfc file there. Change the code to this:
<cfcomponent extends="custom.contentRenderer">
</cfcomponent>
Now your site’s contentRenderer.cfc will pick up the custom methods in your custom.contentRenderer which will in turn pick up all of the default methods in mura.content.contentRenderer. Now you just need to make sure that every site’s contentRenderer extends custom.contentRenderer and you’re good go to.
One thing to watch for here is that if you use the Site Bundle feature, when you deploy the bundle to another server, if the custom.contentRenderer.cfc does not exist, you’ll get errors. So just be mindful of that, and you’re good to go.