コード例 #1
0
 protected override void BeforeRenderContentAreaItemStartTag(TagBuilder tagBuilder, ContentAreaItem contentAreaItem)
 {
     var highLight = HttpContext.Current.Request[Constants.HighlightQueryStringKey];
     if (highLight != null && highLight.Equals(contentAreaItem.GetContent().ContentGuid.ToString()))
         tagBuilder.AddCssClass(HighlightedCssClass);
     base.BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
 }
        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));
            }
        }
        protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem)
        {
            var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem);

            var content = contentAreaItem.GetContent(ContentRepository);

            if (content != null)
            {
                if (tag == null)
                {
                    // Let block decide what to use as default if not
                    // specified on the content area itself
                    tag = GetDefaultDisplayOption(content);
                    if (tag == null)
                    {
                        // Default is always the smalles one we've got
                        tag = WebGlobal.ContentAreaTags.OneThirdWidth;
                    }
                }
                htmlHelper.ViewContext.ViewData["Tag"] = tag;
                return(string.Format("block {0} {1} {2}",
                                     GetTypeSpecificCssClasses(content),
                                     GetCssClassForTag(tag),
                                     tag));
            }
            else
            {
                return(WebGlobal.ContentAreaTags.NoRenderer);
            }
        }
コード例 #4
0
        /// <summary>
        /// Creates custom CSS string based on tag and allows for further Customization for PageData and BlockData that implement ICustomCssInContentArea
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="contentAreaItem"></param>
        /// <returns></returns>
        protected virtual string CustomGetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, int index, int total)
        {
            var    tag                = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem);
            var    content            = contentAreaItem.GetContent(ContentRepository);
            var    customClassContent = content as ICustomCssInContentArea;
            string customCss          = string.Empty;

            // Added custom class if one exists
            if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass))
            {
                customCss = customClassContent.ContentAreaCssClass;
            }

            string firstLastClass = string.Empty;

            if (index == 0)
            {
                firstLastClass = _FirstClass;
            }
            else if (index == total - 1)
            {
                firstLastClass = _LastClass;
            }

            return(string.Format("content-block {0} {1} {2} {3}", customCss, GetCssClassForTag(tag), tag, firstLastClass).Trim());
        }
        protected override string GetContentAreaItemCssClass(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem)
        {
            var childrenCssClass = htmlHelper.ViewData["ChildrenCssClass"];
            if(childrenCssClass != null)
            {
                return childrenCssClass.ToString();
            }

            var tag = GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem);

            var content = contentAreaItem.GetContent(ContentRepository);
            if(content != null)
            {
                if (tag == null )
                {
                    // Let block decide what to use as default if not
                    // specified on the content area itself
                    tag = GetDefaultDisplayOption(content);
                    if (tag == null)
                    {
                        // Default is always the smalles one we've got
                        tag = WebGlobal.ContentAreaTags.OneThirdWidth;
                    }
                }
                htmlHelper.ViewContext.ViewData["Tag"] = tag;
                return string.Format("block {0} {1} {2}",
                    GetTypeSpecificCssClasses(content),
                    GetCssClassForTag(tag),
                    tag);
            }
            else
            {
                return WebGlobal.ContentAreaTags.NoRenderer;
            }
        }
コード例 #6
0
        protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag,
                                                      string cssClass)
        {
            ViewContext viewContext = htmlHelper.ViewContext;
            IContent    content     = contentAreaItem.GetContent(this._contentRepository);

            if (content != null)
            {
                using (new ContentAreaContext(viewContext.RequestContext, content.ContentLink))
                {
                    TemplateModel templateModel = this.ResolveTemplate(htmlHelper, content, templateTag);
                    if ((templateModel != null) || this.IsInEditMode(htmlHelper))
                    {
                        TagBuilder tagBuilder = new TagBuilder(htmlTag);

                        SliderItemSettings itemSettings = viewContext.ViewData["sliderSettings"] as SliderItemSettings;
                        MergeSettings(tagBuilder, itemSettings);
                        if (contentAreaItem.RenderSettings.ContainsKey("sliderSettings"))
                        {
                            itemSettings = contentAreaItem.RenderSettings["sliderSettings"] as SliderItemSettings;
                            MergeSettings(tagBuilder, itemSettings);
                        }
                        // We can override settings per content item
                        tagBuilder.MergeAttributes(contentAreaItem.RenderSettings);

                        BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
                        viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));

                        htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer);

                        viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag));
                    }
                }
            }
        }
コード例 #7
0
        protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass)
        {
            var dictionary = new Dictionary <string, object>();

            dictionary["childrencustomtagname"] = htmlTag;
            dictionary["childrencssclass"]      = cssClass;
            dictionary["tag"] = templateTag;

            dictionary = contentAreaItem.RenderSettings.Concat(
                (
                    from r in dictionary
                    where !contentAreaItem.RenderSettings.ContainsKey(r.Key)
                    select r
                )
                ).ToDictionary(r => r.Key, r => r.Value);

            htmlHelper.ViewBag.RenderSettings = dictionary;
            var content = contentAreaItem.GetContent();

            if (content != null)
            {
                try
                {
                    using (new ContentAreaContext(htmlHelper.ViewContext.RequestContext, content.ContentLink))
                    {
                        var templateModel = ResolveTemplate(htmlHelper, content, templateTag);
                        if ((templateModel != null) || IsInEditMode(htmlHelper))
                        {
                            if (IsInEditMode(htmlHelper))
                            {
                                var tagBuilder = new TagBuilder(htmlTag);
                                AddNonEmptyCssClass(tagBuilder, cssClass);
                                tagBuilder.MergeAttributes <string, string>(
                                    _attributeAssembler.GetAttributes(
                                        contentAreaItem, IsInEditMode(htmlHelper), (bool)(templateModel != null)));
                                BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
                                htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
                                htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer);
                                htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag));
                            }
                            else
                            {
                                htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    _logger.Error("[CustomContentAreaRenderer.RenderContentAreaItem] exception", e);

                    if (PageEditing.PageIsInEditMode)
                    {
                        var errorModel = new ContentRenderingErrorModel(content, e);
                        htmlHelper.RenderPartial("TemplateError", errorModel);
                    }
                }
            }
        }
コード例 #8
0
        protected virtual IContent GetCurrentContent(ContentAreaItem contentAreaItem)
        {
            if (_currentContent == null || !_currentContent.ContentLink.CompareToIgnoreWorkID(contentAreaItem.ContentLink))
            {
                _currentContent = contentAreaItem.GetContent();
            }

            return(_currentContent);
        }
コード例 #9
0
        protected override void BeforeRenderContentAreaItemStartTag(TagBuilder tagBuilder, ContentAreaItem contentAreaItem)
        {
            var highLight = HttpContext.Current.Request[Constants.HighlightQueryStringKey];

            if (highLight != null && highLight.Equals(contentAreaItem.GetContent().ContentGuid.ToString()))
            {
                tagBuilder.AddCssClass(HighlightedCssClass);
            }
            base.BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
        }
コード例 #10
0
        private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentRepository contentRepository)
        {
            var content  = contentAreaItem.GetContent();
            var cssClass = content == null ? String.Empty : content.GetOriginalType().Name.ToLowerInvariant();

            if (content is ICustomCssInContentArea customClassContent && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass))
            {
                cssClass += string.Format(" {0}", customClassContent.ContentAreaCssClass);
            }

            return(cssClass);
        }
コード例 #11
0
        /// <summary>
        /// Allows for additional attributes like style, data- to be added to containing div wrapping the content area item
        /// </summary>
        /// <param name="tagBuilder"></param>
        /// <param name="contentAreaItem"></param>
        protected override void BeforeRenderContentAreaItemStartTag(TagBuilder tagBuilder, ContentAreaItem contentAreaItem)
        {
            var content     = contentAreaItem.GetContent(ContentRepository);
            var customAttrs = content as ICustomAttributesInContentArea;

            if (customAttrs != null)
            {
                tagBuilder.MergeAttributes(customAttrs.CustomAttributes, customAttrs.ReplaceExisitingAttributes);
            }

            base.BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
        }
コード例 #12
0
        private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentRepository contentRepository)
        {
            var content = contentAreaItem.GetContent(contentRepository);
            var cssClass = content == null ? String.Empty : content.GetOriginalType().Name.ToLowerInvariant();

            var customClassContent = content as ICustomCssInContentArea;
            if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass))
            {
                cssClass += string.Format("{0}", customClassContent.ContentAreaCssClass);
            }

            return cssClass;
        }
コード例 #13
0
        private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentLoader contentLoader)
        {
            var content  = contentAreaItem.GetContent(contentLoader);
            var cssClass = content == null ? string.Empty : content.GetOriginalType().Name.ToLowerInvariant();

            // ReSharper disable once SuspiciousTypeConversion.Global
            var customClassContent = content as ICustomCssInContentArea;

            if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass))
            {
                cssClass += string.Format(" {0}", customClassContent.ContentAreaCssClass);
            }

            return(cssClass);
        }
コード例 #14
0
        protected override void RenderContentAreaItem(
            HtmlHelper htmlHelper,
            ContentAreaItem contentAreaItem,
            string templateTag,
            string htmlTag,
            string cssClass)
        {
            var originalWriter = htmlHelper.ViewContext.Writer;
            var tempWriter     = new StringWriter();

            htmlHelper.ViewContext.Writer = tempWriter;

            try
            {
                htmlHelper.ViewContext.ViewData[Constants.BlockIndexViewDataKey] = (int?)htmlHelper.ViewContext.ViewData[Constants.BlockIndexViewDataKey] + 1 ?? 0;

                var content = contentAreaItem.GetContent();

                // persist selected DisplayOption for content template usage (if needed there of course)

                using (new ContentAreaItemContext(htmlHelper.ViewContext.ViewData, contentAreaItem))
                {
                    // NOTE: if content area was rendered with tag (Html.PropertyFor(m => m.Area, new { tag = "..." }))
                    // this tag is overridden if editor chooses display option for the block
                    // therefore - we need to persist original CA tag and ask kindly EPiServer to render block template in original CA tag context
                    var tag = string.IsNullOrEmpty(ContentAreaTag) ? templateTag : ContentAreaTag;

                    base.RenderContentAreaItem(htmlHelper, contentAreaItem, tag, htmlTag, cssClass);
                    var contentItemContent = tempWriter.ToString();
                    var hasEditContainer   = htmlHelper.GetFlagValueFromViewData(Constants.HasEditContainerKey);

                    // we need to render block if we are in Edit mode
                    if (IsInEditMode(htmlHelper) && (hasEditContainer == null || hasEditContainer.Value))
                    {
                        originalWriter.Write(contentItemContent);
                        return;
                    }

                    ProcessItemContent(contentItemContent, contentAreaItem, content, htmlHelper, originalWriter);
                }
            }
            finally
            {
                // restore original writer to proceed further with rendering pipeline
                htmlHelper.ViewContext.Writer = originalWriter;
            }
        }
コード例 #15
0
        protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag, string cssClass)
        {
            var dictionary = new Dictionary <string, object>
            {
                [GlobalConstants.ViewBagProperties.Childrencustomtagname] = htmlTag,
                [GlobalConstants.ViewBagProperties.Childrencssclass]      = cssClass,
                [GlobalConstants.ViewBagProperties.Tag] = templateTag
            };

            dictionary = contentAreaItem.RenderSettings.Concat(
                from r in dictionary
                where !contentAreaItem.RenderSettings.ContainsKey(r.Key)
                select r).ToDictionary(r => r.Key, r => r.Value);

            htmlHelper.ViewBag.RenderSettings = dictionary;
            var content = contentAreaItem.GetContent();

            if (content == null)
            {
                return;
            }

            using (new ContentAreaContext(htmlHelper.ViewContext.RequestContext, content.ContentLink))
            {
                var templateModel = ResolveTemplate(htmlHelper, content, templateTag);
                if ((templateModel == null) && !IsInEditMode(htmlHelper))
                {
                    return;
                }

                if (IsInEditMode(htmlHelper))
                {
                    var tagBuilder = new TagBuilder(htmlTag);
                    AddNonEmptyCssClass(tagBuilder, cssClass);
                    tagBuilder.MergeAttributes(attributeAssembler.Service.GetAttributes(contentAreaItem, IsInEditMode(htmlHelper), templateModel != null));
                    BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
                    htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));
                    htmlHelper.RenderContentData(content, true);
                    htmlHelper.ViewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag));
                }
                else
                {
                    htmlHelper.RenderContentData(content, true);
                }
            }
        }
コード例 #16
0
        private static string GetTypeSpecificCssClasses(ContentAreaItem contentAreaItem, IContentLoader contentLoader)
        {
            var content = contentAreaItem.GetContent(contentLoader);
            var cssClass = content == null ? string.Empty : content.GetOriginalType().Name.ToLowerInvariant();

            // ReSharper disable once SuspiciousTypeConversion.Global
            var customClassContent = content as ICustomCssInContentArea;
            if (customClassContent != null && !string.IsNullOrWhiteSpace(customClassContent.ContentAreaCssClass))
            {
                cssClass += string.Format(" {0}", customClassContent.ContentAreaCssClass);
            }

            return cssClass;
        }
コード例 #17
0
        protected override void RenderContentAreaItem(
            HtmlHelper htmlHelper,
            ContentAreaItem contentAreaItem,
            string templateTag,
            string htmlTag,
            string cssClass)
        {
            var originalWriter = htmlHelper.ViewContext.Writer;
            var tempWriter     = new StringWriter();

            htmlHelper.ViewContext.Writer = tempWriter;

            try
            {
                var content = contentAreaItem.GetContent(ContentRepository);
                base.RenderContentAreaItem(htmlHelper, contentAreaItem, templateTag, htmlTag, cssClass);
                var contentItemContent = tempWriter.ToString();

                if (IsInEditMode(htmlHelper))
                {
                    // we need to render block if we are in Edit mode
                    originalWriter.Write(contentItemContent);
                }
                else
                {
                    var doc = new HtmlDocument();
                    doc.Load(new StringReader(contentItemContent));
                    var blockContentNode = doc.DocumentNode.ChildNodes.FirstOrDefault();

                    if (blockContentNode == null)
                    {
                        return;
                    }

                    // pass node to callback for some fancy modifications (if any)
                    _elementStartTagRenderCallback?.Invoke(blockContentNode, contentAreaItem, content);

                    if (!string.IsNullOrEmpty(blockContentNode.InnerHtml.Trim(null)))
                    {
                        var renderItemContainer = GetFlagValueFromViewData(htmlHelper, "hasitemcontainer");

                        if (!renderItemContainer.HasValue || renderItemContainer.Value)
                        {
                            originalWriter.Write(blockContentNode.OuterHtml);
                        }
                        else
                        {
                            originalWriter.Write(blockContentNode.InnerHtml);
                        }
                    }
                    else
                    {
                        // ReSharper disable once SuspiciousTypeConversion.Global
                        var visibilityControlledContent = content as IControlVisibility;
                        if ((visibilityControlledContent == null) || !visibilityControlledContent.HideIfEmpty)
                        {
                            originalWriter.Write(blockContentNode.OuterHtml);
                        }
                    }
                }
            }
            finally
            {
                // restore original writer to proceed further with rendering pipeline
                htmlHelper.ViewContext.Writer = originalWriter;
            }
        }
コード例 #18
0
        protected override void RenderContentAreaItem(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem, string templateTag, string htmlTag,
            string cssClass)
        {
            ViewContext viewContext = htmlHelper.ViewContext;
            IContent content = contentAreaItem.GetContent(this._contentRepository);
            if (content != null)
            {
                using (new ContentAreaContext(viewContext.RequestContext, content.ContentLink))
                {
                    TemplateModel templateModel = this.ResolveTemplate(htmlHelper, content, templateTag);
                    if ((templateModel != null) || this.IsInEditMode(htmlHelper))
                    {
                        TagBuilder tagBuilder = new TagBuilder(htmlTag);

                        SliderItemSettings itemSettings = viewContext.ViewData["sliderSettings"] as SliderItemSettings;
                        MergeSettings(tagBuilder, itemSettings);
                        if (contentAreaItem.RenderSettings.ContainsKey("sliderSettings"))
                        {
                            itemSettings = contentAreaItem.RenderSettings["sliderSettings"] as SliderItemSettings;
                            MergeSettings(tagBuilder, itemSettings);
                        }
                        // We can override settings per content item
                        tagBuilder.MergeAttributes(contentAreaItem.RenderSettings);

                        BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
                        viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.StartTag));

                        htmlHelper.RenderContentData(content, true, templateModel, _contentRenderer);

                        viewContext.Writer.Write(tagBuilder.ToString(TagRenderMode.EndTag));
                    }
                }
            }
        }
コード例 #19
0
        protected override void RenderContentAreaItem(
            HtmlHelper htmlHelper,
            ContentAreaItem contentAreaItem,
            string templateTag,
            string htmlTag,
            string cssClass)
        {
            var originalWriter = htmlHelper.ViewContext.Writer;
            var tempWriter = new StringWriter();
            htmlHelper.ViewContext.Writer = tempWriter;

            try
            {
                var content = contentAreaItem.GetContent(ContentRepository);
                base.RenderContentAreaItem(htmlHelper, contentAreaItem, templateTag, htmlTag, cssClass);
                var contentItemContent = tempWriter.ToString();

                if (IsInEditMode(htmlHelper))
                {
                    // we need to render block if we are in Edit mode
                    originalWriter.Write(contentItemContent);
                }
                else
                {
                    var doc = new HtmlDocument();
                    doc.Load(new StringReader(contentItemContent));
                    var blockContentNode = doc.DocumentNode.ChildNodes.FirstOrDefault();

                    if (blockContentNode == null)
                    {
                        return;
                    }

                    // pass node to callback for some fancy modifications (if any)
                    _elementStartTagRenderCallback?.Invoke(blockContentNode, contentAreaItem, content);

                    if (!string.IsNullOrEmpty(blockContentNode.InnerHtml.Trim(null)))
                    {
                        var renderItemContainer = GetFlagValueFromViewData(htmlHelper, "hasitemcontainer");

                        if (!renderItemContainer.HasValue || renderItemContainer.Value)
                        {
                            originalWriter.Write(blockContentNode.OuterHtml);
                        }
                        else
                        {
                            originalWriter.Write(blockContentNode.InnerHtml);
                        }
                    }
                    else
                    {
                        // ReSharper disable once SuspiciousTypeConversion.Global
                        var visibilityControlledContent = content as IControlVisibility;
                        if ((visibilityControlledContent == null) || !visibilityControlledContent.HideIfEmpty)
                        {
                            originalWriter.Write(blockContentNode.OuterHtml);
                        }
                    }
                }
            }
            finally
            {
                // restore original writer to proceed further with rendering pipeline
                htmlHelper.ViewContext.Writer = originalWriter;
            }
        }