November Happy Hour will be moved to Thursday December 5th.
November Happy Hour will be moved to Thursday December 5th.
What are you trying to achieve exactly? There have been other questions with answers recently where developers have removed both the <div> tags that surround the content area and <div> tags that surround each individual block. This would then allow you to control the markup 100% from the razor files for the individual blocks.
Hi @Mark Stott,
I'm having some custom ViewData variables, passed it to RenderContentAreaItem via .PropertyFor func in razor. In there I need bind ViewData variables as div attributes to content area render result. With CMS 11.x I can parse context writer result to html dom and do anything with that, when trying with cms 12, stucking with TagBuilder :(
protected override void RenderContentAreaItem(IHtmlHelper htmlHelper, ContentAreaItem contentAreaItem,string templateTag, string htmlTag, string cssClass)
{
var originalWriter = htmlHelper.ViewContext.Writer;
var tempWriter = new StringWriter();
htmlHelper.ViewContext.Writer = tempWriter;
var content = contentAreaItem.InlineBlock;
base.RenderContentAreaItem(htmlHelper, contentAreaItem, templateTag, htmlTag, cssClass);
// Content having TagBuilder issues here
var contentItemContent = tempWriter.ToString();
// Parse contentItemContent to html dom and do anything here - with CMS 12 - having TagBuilder issue
}
Before I try and replicate the issue you're having, have you recently updated your visual studio and is this a symptom of Microsoft breaking the tag helpers as per this article:
Hello Dzung,
I had a look at this and if you are trying to add additional attributes to the container tag for the block based on the http context, then you could look at extending or overwriting the IContentAreaItemAttributeAssembler interface.
public class CustomContentAreaItemAttributeAssembler : IContentAreaItemAttributeAssembler
{
private readonly IHttpContextAccessor _contextAccessor;
public CustomContentAreaItemAttributeAssembler(IHttpContextAccessor contextAccessor)
{
_contextAccessor = contextAccessor;
}
public IDictionary<string, string> GetAttributes(ContentAreaItem contentAreaItem, bool isRenderedInEditMode, bool hasRenderer)
{
var httpContext = _contextAccessor.HttpContext;
return new Dictionary<string, string>
{
{ "test", "foo" }
};
}
}
This will result in this:
<div test="foo">
<!-- block render gets added here -->
</div>
Hello @Stott,
Is there any other way add custom attributes, I need to access ViewData to get custom attribute value. In RenderContentAreaItem function I can do it via IHtmlHelper.ViewContext. I'm passing ViewData to ViewContent by bellow way:
@Html.PropertyFor(model=>model.ContentAreaItem,
new ViewData() {
// All custom attributes need set to Content area block html wrapper
"customAttr1" : "attr1_value",
"customAttr2" : "attr2_value",
"customAttr2" : "attr2_value"
})
I'm trying to add some custom attribute while content area rendering depend on httpContext.
Created custom content area renderer but I get Microsoft.AspNetCore.Mvc.Rendering.TagBuilder+RenderTagHtmlContent at both start and end.
Seem base.RenderContentAreaItem from Epi packages having issue with tagBuilder
Does anyone have work around solution, please advise.