Custom Sub Scopes - Mura Docs v6

Custom Sub Scopes

You can also create custom Mura Scope keys. These keys are also available to all other Mura Scope instances instantiated for the remainder of the request life cycle.

$.setCustomMuraScopeKey()

To create a custom Mura Scope key, add a method to the site's or theme's eventHandler.cfc onSiteRequestStart() method as follows:

public void function onSiteRequestStart($) {
var customKey = 'This is my custom key!';
$.setCustomMuraScopeKey('customKey', customKey);
}

To reference the custom key, you could then use:

#$.customKey#

The custom key does not necessarily have to be a string. You could, for example, pass in an object:

public void function onSiteRequestStart($) {
var customKey = new someObject();
$.setCustomMuraScopeKey('customKey', customKey);
}

Then, to reference any of the objects methods, you could use:

#$.customKey.doSomeMethod()#

This assumes someObject.cfc has a public or remote method named doSomeMethod().