Sub Scopes - Mura Docs v6

Sub Scopes

There are several sub-scopes within Mura. Sub-scopes have their own sets of helper methods as well. Let's take a quick look at some of the main ones.

Content Scope

The Content scope wraps the current front end request's contentBean. This gives us both easy access to the contentBean itself as well as a host of 'helper' functions.

The following returns the full contentBean of the current content node:

$.content();

You can also access the parent's full contentBean of the current front end request using:

$.content().getParent();

Accessing Values (Getters)

All values inside a standard contentBean are accessible through the Content Scope. These are listed in order of best practice, however all will return the same value.

$.content('title');
$.content().getTitle();
$.content().getValue('title');

Setting Values (Setters)

Content values can be “set” using the following notation:

$.content('title', 'Your New Title');
$.content().setTitle('Your New Title');
$.content().setValue('title', 'Your New Title');

A Few Helpers

The sub-scopes also include a selection of helper objects, each designed to make working with the content easier.

$.content().getAllValues();
$.content().set({args});
$.content().save();
$.content().delete();
$.content().getParent();
$.content().hasParent();
$.content().getIsNew();
$.content().getURL({queryString});
$.content().getImageURL(size={'small'|'medium'|'large'|'customdefinedsize'|'custom'});
$.content().getImageURL(height={numberOfPixels or 'auto'}, width={numberOfPixels or 'auto'});
$.content().hasDrafts();
$.content().deleteVersion();
$.content().deleteVersionHistory();
$.content().getKidsIterator([{liveOnly},{aggregation}]);
// NOTE: Queries do NOT contain extended attributes!
$.content().getKidsQuery([{liveOnly},{aggregation}]);
$.content().getCrumbIterator();
$.content().getCrumbArray();
$.content().getCommentsIterator();
$.content().getCommentsQuery();
$.content().getCategoriesIterator();
$.content().getCategoriesQuery();
$.content().getKidsCategoryIterator();
$.content().getKidsCategoryQuery();
$.content().getVersionHistoryIterator();
$.content().getVersionHistoryQuery();
$.content().getRelatedContentIterator();
$.content().getRelatedContentQuery();
$.content().setNewFile({filePath/URL});
$.content().getStats().getComments();

Important: The second argument of "siteID" is only required when the siteID is not defined or is not the same as the siteID value set in the current Mura Scope's event (e.g., $.event("siteID”)).

Comment Scope

$.comment().getAllValues();
$.comment().set({args});
$.comment().save();
$.comment().delete();
$.comment().getUser();
$.comment().getParent();
$.comment().getIsNew();
$.comment().getKidsIterator([{boolean:isEditor}]);
$.comment().getKidsQuery([{boolean:isEditor}]);
$.comment().getCrumbIterator();
$.comment().getCrumbQuery();

Category Scope

category.set({args});
category.save();
category.delete();
category.getParent();
category.getIsNew();
category.getKidsIterator();
category.getKidsQuery();
category.getCrumbIterator();
category.getCrumbQuery();

Current User Scope

The Current User scope wraps the Session User Facade object, which in turn wraps the session.mura struct. The main benefit of the Session Facade is that it knows how and when to retrieve data that is not normally stored in the session.mura struct, including extended attributes.

$.currentUser();

A Few Helpers

$.currentUser().getAllValues();
$.currentUser().getMembershipsIterator();
$.currentUser().readAddress(addressName={addressName});
$.currentUser().isLoggedIn();
$.currentUser().isInGroup('Some Group Name');

You can also save any changes that may be made to user during a session:

$.currentUser('fname', 'John');
$.currentUser('lname', 'Doe');
$.currentUser().save();

Site Config Scope

Site Config scope contains site configuration settings and environment variables. This scope is specific to the site in which you're working at the moment.

$.siteConfig();

Key Methods

These methods return the starting URL path to be used with things like JavaScript and CSS file references:

$.siteConfig('assetPath');
$.siteConfig('themeAssetPath');

These methods return the starting file path to be used for <cfinclude>:

$.siteConfig('includePath');
$.siteConfig('themeIncludePath');

These methods return the starting component path (or dotted-notation path) for object instantiation:

$.siteConfig('assetMap');
$.siteConfig('themeAssetMap');

This returns an instance of the site's contentRenderer for use with static methods:

$.siteConfig('contentRenderer');

This returns an instance of the theme's contentRenderer for use with static methods:

$.siteConfig('themeRenderer');

Global Config Scope

The Global Config scope wraps the global configuration for your Mura instance, found under:
/config/settings.ini.cfm.

$.globalConfig();

You can also access any custom key-values that have been created in the /config/settings.ini.cfm by passing in the key used to set the value in the file:

$.globalConfig('yourCustomKey');

Event Scope

The $.event() scope is a special case. On every request, Mura generates a global event scope (accessible via $.getGlobalEvent()), and there are also contextual events which are fired when specific blocks of code or actions occur. For instance, when content is saved, a contextual event of onBeforeSave() is fired.

$.event() is always available, and is a handy place to access the current SiteID via $.event('siteID'). Additional examples will be covered in the Events section.