diff --git a/src/Umbraco.Web/Editors/MacroRenderingController.cs b/src/Umbraco.Web/Editors/MacroRenderingController.cs
index 7aabff6822..33a58328b9 100644
--- a/src/Umbraco.Web/Editors/MacroRenderingController.cs
+++ b/src/Umbraco.Web/Editors/MacroRenderingController.cs
@@ -142,7 +142,7 @@ namespace Umbraco.Web.Editors
//need to create a specific content result formatted as HTML since this controller has been configured
//with only json formatters.
result.Content = new StringContent(
- _componentRenderer.RenderMacro(pageId, m.Alias, macroParams).ToString(),
+ _componentRenderer.RenderMacroForContent(publishedContent, m.Alias, macroParams).ToString(),
Encoding.UTF8,
"text/html");
diff --git a/src/Umbraco.Web/IUmbracoComponentRenderer.cs b/src/Umbraco.Web/IUmbracoComponentRenderer.cs
index 4dc9036e6b..f05afe3f6b 100644
--- a/src/Umbraco.Web/IUmbracoComponentRenderer.cs
+++ b/src/Umbraco.Web/IUmbracoComponentRenderer.cs
@@ -42,5 +42,18 @@ namespace Umbraco.Web
/// The parameters.
///
IHtmlString RenderMacro(int contentId, string alias, IDictionary parameters);
+
+ ///
+ /// Renders the macro with the specified alias, passing in the specified parameters.
+ ///
+ /// An IPublishedContent to use for the context for the macro rendering
+ /// The alias.
+ /// The parameters.
+ /// A raw HTML string of the macro output
+ ///
+ /// Currently only used when the node is unpublished and unable to get the contentId item from the
+ /// content cache as its unpublished. This deals with taking in a preview/draft version of the content node
+ ///
+ IHtmlString RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters);
}
}
diff --git a/src/Umbraco.Web/UmbracoComponentRenderer.cs b/src/Umbraco.Web/UmbracoComponentRenderer.cs
index 0373c73724..aa4cbefe7b 100644
--- a/src/Umbraco.Web/UmbracoComponentRenderer.cs
+++ b/src/Umbraco.Web/UmbracoComponentRenderer.cs
@@ -102,6 +102,15 @@ namespace Umbraco.Web
return RenderMacro(content, alias, parameters);
}
+
+ public IHtmlString RenderMacroForContent(IPublishedContent content, string alias, IDictionary parameters)
+ {
+ if(content == null)
+ throw new InvalidOperationException("Cannot render a macro, IPublishedContent is null");
+
+ return RenderMacro(content, alias, parameters);
+ }
+
///
/// Renders the macro with the specified alias, passing in the specified parameters.
///