Dynamically Define a Mura CMS Theme's Display Regions

A question came up recently regarding Mura CMS and how to alter the available content object display regions. This is actually quite simple to control from within the Admin area of the site by going to Site Settings > Select the Site > Select the Display Regions Tab and then choose the Number of Display Regions, select the Primary Display Region and define the Display Region Names as a carrot "^" delimited list.

However, this particular inquisitor was actually interested in how to control these settings from within a specific theme itself. Luckily, as with most things in Mura, it really isn't all that difficult to do.

Since this is not something we would want to happen everytime a page loads, it would probably work best to use the onApplicationLoad() method in the theme's eventHandler.cfc. This way, it will only be executed whenever the entire application is loaded. The next thing we need to figure out is what methods we need to call and how to tell Mura to save our settings.

So, as I've pointed other people in the past, most all of the important methods that comprise the Mura engine can be found under the /requirements/mura/ directory. Since we're dealing with Site Settings, we'll want to review the methods available to us under the 'settings' directory. There you'll find settingsManager.cfc among other files. Within this file, you'll be able to locate a method called update() which takes an argument called data which is required to be a struct/object. The data object should have a key which contains the siteid of the site we wish to edit the settings for. Then, we can update any of the available settings we wish!

Here's some code for you to play around with:

<cffunction name="onApplicationLoad">
    <cfargument name="$" />
        var local = {};
        // dynamically alter the available display regions from within a theme
        local.data = {
            siteID = $.siteConfig('siteid')
            , columnCount = 5
            , primaryColumn = 3
            , columnNames = 'Test^Left Column^Main Content^Right Column^Footer'
        local.siteBean = $.getBean('settingsManager');

If you're wondering what settings are available to you, simply do a dump of all the existing values:

<cfdump var="#$.siteConfig().getAllValues()#" />

Hope that helps someone else trying to update their Mura Site Settings from within the theme itself.


© 2024, Stephen J. Withington, Jr.  |  Hosted by Hostek.com

Creative Commons License   |   This work is licensed under a Creative Commons Attribution 3.0 Unported License.