Skip to content

Instantly share code, notes, and snippets.

@nathanwoulfe
Last active March 2, 2020 23:02
Show Gist options
  • Save nathanwoulfe/974232ee8c62f4bb12e87193bee85647 to your computer and use it in GitHub Desktop.
Save nathanwoulfe/974232ee8c62f4bb12e87193bee85647 to your computer and use it in GitHub Desktop.
Processing Umbraco macros
///
/// Extension on UmbracoHelper to return a processed macro as a string...
///
public static IHtmlString RenderMacroScript(this UmbracoHelper helper, string language, string fileLocation, IDictionary<string, object> parameters)
{
var ctrl = new umbraco.presentation.templateControls.Macro
{
Language = language,
FileLocation = fileLocation,
};
foreach (var parameter in parameters)
{
ctrl.Attributes.Add(parameter.Key, parameter.Value.ToString());
}
return new HtmlString(ctrl.RenderControlToString());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment