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 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$}");