internal static string ParseInternalLinks(string text, bool preview, UmbracoContext umbracoContext) { using (umbracoContext.ForcedPreview(preview)) // force for url provider { text = ParseInternalLinks(text, umbracoContext.UrlProvider); } return(text); }
private HttpResponseMessage GetMacroResultAsHtml(string macroAlias, int pageId, IDictionary <string, object> macroParams) { var m = _macroService.GetByAlias(macroAlias); if (m == null) { throw new HttpResponseException(HttpStatusCode.NotFound); } var publishedContent = UmbracoContext.Content.GetById(true, pageId); //if it isn't supposed to be rendered in the editor then return an empty string //currently we cannot render a macro if the page doesn't yet exist if (pageId == -1 || publishedContent == null || m.DontRender) { var response = Request.CreateResponse(); //need to create a specific content result formatted as HTML since this controller has been configured //with only json formatters. response.Content = new StringContent(string.Empty, Encoding.UTF8, "text/html"); return(response); } // When rendering the macro in the backoffice the default setting would be to use the Culture of the logged in user. // Since a Macro might contain thing thats related to the culture of the "IPublishedContent" (ie Dictionary keys) we want // to set the current culture to the culture related to the content item. This is hacky but it works. // fixme // in a 1:1 situation we do not handle the language being edited // so the macro renders in the wrong language var culture = publishedContent.GetCultureFromDomains(); if (culture != null) { Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo(culture); } // must have an active variation context! _variationContextAccessor.VariationContext = new VariationContext(culture); using (UmbracoContext.ForcedPreview(true)) { var result = Request.CreateResponse(); //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(), Encoding.UTF8, "text/html"); return(result); } }