Resolving macros using the API
If you need to process macro expressions inside text values in your custom code, use the MacroResolver.Resolve method. Specify the string where you want to resolve macros as the method’s input parameter.
For example:
using CMS.MacroEngine;
...
// Resolves macros in the specified string using a new instance of the global resolver
string resolvedTextGlobal = MacroResolver.Resolve("The current user is: {% CurrentUser.UserName %}");
The method evaluates the macros using a new instance of the global resolver and automatically ensures thread-safe processing.
Macro resolvers are system components that provide the processing of macros. The resolvers are organized in a hierarchy that allows child resolvers to inherit all macro options from the parent. The global resolver is the parent of all other resolvers in the system.
Resolving macros on the live site
Certain macros that are only intended for the Xperience administration interface do not work when resolving macros from the code of the live site application. For example, macros that return the HTML code of font icons used in the administration interface. Such macros are only available within the code libraries of the administration application.
Resolving localization macros
If you only need to resolve localization macros in text, call the CMS.Helpers.ResHelper.LocalizeString method.
using CMS.Helpers;
...
// Resolves localization macros in text
string localizedResult = ResHelper.LocalizeString("{$general.actiondenied$}");