Allows unpublished content to render a macro HTML in the RTE

(cherry picked from commit 3680f22321)
This commit is contained in:
Warren Buckley
2020-06-10 14:33:32 +01:00
committed by Thomas Andresen
parent f716754253
commit c99798ac1b
3 changed files with 23 additions and 1 deletions

View File

@@ -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");

View File

@@ -42,5 +42,18 @@ namespace Umbraco.Web
/// <param name="parameters">The parameters.</param>
/// <returns></returns>
IHtmlString RenderMacro(int contentId, string alias, IDictionary<string, object> parameters);
/// <summary>
/// Renders the macro with the specified alias, passing in the specified parameters.
/// </summary>
/// <param name="content">An IPublishedContent to use for the context for the macro rendering</param>
/// <param name="alias">The alias.</param>
/// <param name="parameters">The parameters.</param>
/// <returns>A raw HTML string of the macro output</returns>
/// <remarks>
/// 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
/// </remarks>
IHtmlString RenderMacroForContent(IPublishedContent content, string alias, IDictionary<string, object> parameters);
}
}

View File

@@ -102,6 +102,15 @@ namespace Umbraco.Web
return RenderMacro(content, alias, parameters);
}
public IHtmlString RenderMacroForContent(IPublishedContent content, string alias, IDictionary<string, object> parameters)
{
if(content == null)
throw new InvalidOperationException("Cannot render a macro, IPublishedContent is null");
return RenderMacro(content, alias, parameters);
}
/// <summary>
/// Renders the macro with the specified alias, passing in the specified parameters.
/// </summary>