PluginConfig - Mura Docs v6

PluginConfig

Access to the pluginConfig object depends on the base object that's being extended.

If the component extends='mura.plugin.pluginGenericEventHandler' then use:

variables.pluginConfig

If the component extends='mura.cfobject' then use:

getPlugin({pluginID | moduleID | package})

The pluginConfig provides developers with access to the properties configured in the /plugin/config.xml{.cfm}.

var setting = pluginConfig.getSetting({setting name});

As well as plugin-specific Application and Session objects.

Retrieving a Plugin's pluginConfig

If you need to retrieve a plugin's pluginConfig object from outside of that plugins normal phase of execution you can access it by using the base extends='mura.cfobject' method getPlugin(). This method takes a single argument of either pluginID, moduleID, name or package.

$.getPlugin({pluginID | moduleID | name | package})

Retrieving a pluginConfig by the value of the plugin's 'Package' element in the /plugin/config.xml allows developers to have a consistent way of referencing the plugin from one instance of Mura to another.

Application Object

The pluginConfig object has it own application object that provides a container for key value pairs that you would like to persist for the plugin. It has an optional purge boolean argument to tell the pluginConfig to return a brand new object which defaults to false.

// in the following statement, true = purge application
var pApp = pluginConfig.getApplication(true);
pApp.setValue('myFavoriteColor', 'blue');
pVar = pApp.getValue('myFavoriteColor');

Session Object

The pluginConfig object has it own session object that provides a container for key value pairs that you would like to persist for users interacting with the plugin. It has an optional boolean purge argument to tell the pluginConfig to return a brand new object which defaults to false.

var pSession =variables.pluginConfig.getSession(true); // true = purge session
pSession.setValue('myFavoriteColor', 'pink');
pSession=pSession.getValue('pink');

Retrieving a Plugin's Assigned Sites

You can retrieve a query of a plugin's assigned sites by using the pluginConfig.getAssignedSites() method.

<cfcsript>
rsSites=getPlugin('myPlugin').getAssignedSites();
</cfscript>
<cfoutput>
<cfloop query="rsSites">
#rsSites.siteid#<br/>
</cfloop>
</cfoutput>

Adding to the HTMLHead or HTMLFoot Queues

The pluginConfig object also allow developers to add the current requests HTMLHeadQueue:

pluginConfig.addToHTMLHeadQueue({path});

The "path" argument is a file path starting from the root of your plugin.

  • {plugin root}/htmlhead/inc.cfm

The contents of "inc.cfm":

<link href="#pluginPath#css/contributor_tools.css" type="text/css" />

Add inc.cfm to the HTMLHeadQueue:

pluginConfig.addToHTMLHeadQueue("htmlhead/inc.cfm");

One import note is that if the code that you are injecting into the head of the page requires the JS library to be loaded (e.g., jquery) you need to explicitly do so.

$.loadJSLib();
pluginConfig.addToHTMLHeadQueue('htmlhead/inc.cfm');
pluginConfig.addToHTMLFootQueue('htmlfoot/inc.cfm');