Skip to content
azturner edited this page Nov 5, 2012 · 8 revisions

Rock has a place where your custom blocks and other code (Jobs, Transactions, etc.) can access globally configured setting values. To retrieve a value, use the Rock.Web.Cache.GlobalAttributes.GetValue(string attributeKey) method as seen here:

    var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
    string value = globalAttributes.GetValue("EmailServer");

To store a new value in a Global Attribute you can use the SetValue() method like this:

    var globalAttributes = Rock.Web.Cache.GlobalAttributesCache.Read();
    globalAttributes.SetValue("EmailServer", "server.mydomain.com", null, true);

MERGE FIELDS

The values of global attributes can also have merge fields in them that contain other global attributes. For example, say you are working on an email templates and several of the templates should have the same header and footer (common for styling). These headers and footers however may have settings in them like the background color or logo url. This is all possible with 'global attribute nesting'. The 'header' attribute can include the 'background-color' attribute and be used in the email template. This nesting can be n levels deep, however, simpler is better.

The administrator must be very careful to not create circular references (A includes B which includes A) as these will cause the system to enter a loop and cause it to run out of memory.

Clone this wiki locally