using System;
using System.Collections;
using System.Globalization;
using System.IO;
using System.Web;
using System.Web.UI;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Web.Templates;
using umbraco;
using System.Collections.Generic;
using umbraco.presentation.templateControls;
using Umbraco.Core.Exceptions;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Composing;
using Umbraco.Web.Macros;
namespace Umbraco.Web
{
///
/// Methods used to render umbraco components as HTML in templates
///
///
/// Used by UmbracoHelper
///
internal class UmbracoComponentRenderer : IUmbracoComponentRenderer
{
private readonly UmbracoContext _umbracoContext;
public UmbracoComponentRenderer(UmbracoContext umbracoContext)
{
_umbracoContext = umbracoContext;
}
///
/// Renders the template for the specified pageId and an optional altTemplateId
///
///
/// If not specified, will use the template assigned to the node
///
public IHtmlString RenderTemplate(int pageId, int? altTemplateId = null)
{
var templateRenderer = new TemplateRenderer(_umbracoContext, pageId, altTemplateId);
using (var sw = new StringWriter())
{
try
{
templateRenderer.Render(sw);
}
catch (Exception ex)
{
sw.Write("", pageId, ex);
}
return new HtmlString(sw.ToString());
}
}
///
/// Renders the macro with the specified alias.
///
/// The alias.
///
public IHtmlString RenderMacro(string alias)
{
return RenderMacro(alias, new { });
}
///
/// Renders the macro with the specified alias, passing in the specified parameters.
///
/// The alias.
/// The parameters.
///
public IHtmlString RenderMacro(string alias, object parameters)
{
return RenderMacro(alias, parameters.ToDictionary