protected override void RenderContentAreaItem(
            HtmlHelper htmlHelper,
            ContentAreaItem contentAreaItem,
            string templateTag,
            string htmlTag,
            string cssClass)
        {
            var content = contentAreaItem.GetContent(ContentRepository);

            if (content == null)
            {
                return;
            }

            var serialisedContent = EpiServerDonutHelper.SerializeBlockContentReference(content);

            using (var textWriter = new StringWriter())
            {
                var cutomHtmlHelper = EpiServerDonutHelper.CreateHtmlHelper(htmlHelper.ViewContext.Controller, textWriter);
                EpiServerDonutHelper.RenderContentData(cutomHtmlHelper, content, string.Empty);

                var tagBuilder    = CreateContentAreaSeperatorHtmlTags(contentAreaItem, htmlTag, cssClass);
                var epiServerHtml = EpiServerDonutHelper.CreateContentAreaDonutTag(tagBuilder, serialisedContent, textWriter.ToString());

                htmlHelper.RenderXhtmlString(new XhtmlString(epiServerHtml));
            }
        }
        public static void DonutForContent(this HtmlHelper htmlHelper, IContent content)
        {
            var serialisedContent = EpiServerDonutHelper.SerializeBlockContentReference(content);

            using (var textWriter = new StringWriter())
            {
                var cutomHtmlHelper = EpiServerDonutHelper.CreateHtmlHelper(htmlHelper.ViewContext.Controller, textWriter);
                EpiServerDonutHelper.RenderContentData(cutomHtmlHelper, content, string.Empty);

                var outputString = string.Format("<!--Donut#{0}#-->{1}<!--EndDonut-->", serialisedContent, textWriter);

                var htmlString = new XhtmlString(outputString);
                htmlHelper.RenderXhtmlString(htmlString);
            }
        }
Beispiel #3
0
        public string ReplaceDonutHoleContent(string content, ControllerContext filterContext, OutputCacheOptions options)
        {
            if (filterContext.IsChildAction &&
                (options & OutputCacheOptions.ReplaceDonutsInChildActions) != OutputCacheOptions.ReplaceDonutsInChildActions)
            {
                return(content);
            }

            return(DonutHoleRegex.Replace(content, match =>
            {
                var contentReference = JsonConvert.DeserializeObject <ContentReference>(match.Groups[1].Value);

                if (contentReference == null)
                {
                    return null;
                }

                var htmlToRenderWithoutDonutComment = new StringBuilder();

                using (var stringWriter = new StringWriter())
                {
                    var htmlHelper = EpiServerDonutHelper.CreateHtmlHelper(filterContext.Controller, stringWriter);

                    var repo = ServiceLocator.Current.GetInstance <IContentRepository>();
                    var epiContentToRender = repo.Get <IContent>(contentReference);

                    var openTag = OpenTagRegex.Match(match.Groups[1].ToString()).Groups[1].ToString();

                    if (!string.IsNullOrEmpty(openTag))
                    {
                        htmlToRenderWithoutDonutComment.Append(openTag);
                    }

                    EpiServerDonutHelper.RenderContentData(htmlHelper, epiContentToRender, string.Empty);
                    htmlToRenderWithoutDonutComment.Append(stringWriter.ToString());

                    var closeTag = CloseTagRegex.Match(match.Groups[1].ToString()).Groups[1].ToString();

                    if (!string.IsNullOrEmpty(closeTag))
                    {
                        htmlToRenderWithoutDonutComment.Append(closeTag);
                    }
                }

                return htmlToRenderWithoutDonutComment.ToString();
            }));
        }