Mura CMS Quick Tip: Dynamic Template Rendering

CFML , ColdFusion , Mura CMS Add comments

In Mura CMS, there is the concept of templates that make up your site theme. Your theme can have multiple templates, such as a two-column template and a 3 column template which can be assigned to individual pages in your site. You can read more about templates in Mura here. Recently, while working on a Mura site, I wanted my pages to be able to dynamically use either a 2- or a 3-column template depending on whether something was assigned to the right column display region (which was display region #3 in this site).

So I whipped up this template named default.cfm:

<cfif len( trim($.dspObjects(3)) )>
<cfinclude template="three_column.cfm" />
<cfinclude template="two_column_SL.cfm" />

So basically it checks to see if anything was assigned to the right column display region. If so, the 3 column template is rendered. If not it defaults to 2 columns. This way, I can just set all pages to the default template and let the content determine whether 2 or 3 columns are used.

9 responses to “Mura CMS Quick Tip: Dynamic Template Rendering”

  1. Sean Schroeder Says:
    Great idea and tip, Tony. Thanks for sharing!
  2. Glyn Says:
    Simple, but nice idea. thanks for this.
  3. Andy Says:
    Me likey. Thanks.
  4. Matt Levine Says:
    Great post! That kind of dynamic template switching is Awesome. One small change that I would do is set the returned value of the dspObjects() call to a variable and then test and render that variable in the template.

    <cfset objects3=trim($.dspObjects(3))>
    <cfif len( objects3 )>
    <cfinclude template="three_column.cfm" />
    <cfinclude template="two_column_SL.cfm" />

    And then just output the objects3 variable where you would normally call $.dspObjects(3) in three_column.cfm. This is because if you have any forms or actions items in that region and you run dspObjects() twice you may collect the data or take the action twice.
  5. Tony Garcia Says:
    Thanks for that tip -- I didn't think of that!
  6. zam Says:
    Hey very good eample of dynamic template rendering, works good :)
  7. lewaters Says:
    best example thanks for sharing it
  8. orchid Says:
    nice tips
  9. Risk Management Plan Says:
    Informative post, I’ll definitely try out some of your tips. I’m currently using all in to help me out.but as i see tips are very useful.

Leave a Reply

Leave this field empty

Powered by Mango Blog. Design and Icons by N.Design Studio