Only the display option will actually be passed along as tag in your case. That means that your default controller will be used since it's marked as default (both controllers support the tag). The tag you specify in
@Html.PropertyFor(x => x.ContentArea, new { Tag = "ContentAreaRibbonBlock", HasContainer = true, CssClass = "row", ChildrenCssClass = "dynamic-box" })
will be ignored.
Inherit EPiServer.Web.Mvc.Html.ContentAreaRenderer and change the method for GetContentAreaItemTemplateTag to change this behaviour if needed.
Hi Daniel,
That is done now. But I've been trying to figure out how I can spot it the current ContentAreaItem was inserted in a content area with my "ContentAreaRibbonBlock" tag?
Got any ideas?
Thanks!
If you inherit ContentAreaRenderer you can always add logging with ILogger interface to see what is coming in...
The final solution to my issue was to override ContentAreaRenderer, and override its method 'GetContentAreaItemTemplateTag', as Daniel said.
But here's the code I ended up with:
protected override string GetContentAreaItemTemplateTag(HtmlHelper htmlHelper, ContentAreaItem contentAreaItem) { string tag = htmlHelper.ViewContext.ViewData[RenderSettings.Tag] as string; DisplayOption displayOption = contentAreaItem.LoadDisplayOption(); // If no tag was specified in the view, and a display option was set => use that. if (tag == null && displayOption != null) { return displayOption.Tag; } // If a tag was specified in the view => use that. if (tag != null) { return tag; } // Fallback return base.GetContentAreaItemTemplateTag(htmlHelper, contentAreaItem); }
The comments should explain my code.
Thanks again, Daniel.
Block type: ContentBlock
Default controller:
Controller for rendering a ContentBlock differently:
Content area that has my special tag to differentiate rendering:
The Constants.ContentAreaTags properties are also used as DisplayOptions from within Episerver edit mode.
When I insert a ContentBlock in this area you see above without applying a DisplayMode, it renders fine. But when I apply a DisplayOptions, ex. Column4 = "col-sm-4", it's rendered by my Default controller.
How is that possible? My ContentBlockForRibbonController has tags values that are more specific than ContentBlockController...