Try our conversational search powered by Generative AI!

Customise the Outer div of Episerver Blocks



Is it possible to customise the outer div that is created by Episerver Blocks. I can see that it is possible to override the GetContentAreaItemCssClass method but is there a way that you can add other attributes to the div?

Can you override other methods?


Feb 09, 2016 10:01

You can override BeforeRenderContentAreaItemStartTag.

protected override void BeforeRenderContentAreaItemStartTag(TagBuilder tagBuilder,
            ContentAreaItem contentAreaItem)
            tagBuilder.Attributes.Add("id", id);
            base.BeforeRenderContentAreaItemStartTag(tagBuilder, contentAreaItem);
Feb 09, 2016 11:19


Great - is there anyway that I can prevent this outer div from being created?


Feb 10, 2016 10:28

The DIVs are required for the CMS experience and so are rendered in to the CMS editor to be consistent. As a note when using @Html.PropertyFor you can passing an object which dictates what the surrounding element and css classes should be e.g.

 @Html.PropertyFor(model => model.CurrentBlock.ClientLogos, new
    CustomTag = "ul",
    CssClass = "list",
    ChildrenCustomTagName = "li",
    ChildrenCssClass = "list_item"
CustomTag = The outer wrapper for the ContentArea
CssClass = Is the class on that outer wrapper
ChildrenCustomTagName = The tag for each block that's rendered out in the ContentArea
ChildrenCssClass = The css class for each block that's rendered out in the ContentArea

Edited, Feb 10, 2016 16:48

In your PropertyFor you could also add "hascontainer = false", this will remove the container div that wraps the content area.

Edited, Feb 11, 2016 7:10

Yes it is possible to remove it but personally we prefer not to. The DOM structure that is rendered out should be consistent against the front end and the back end preview IMO and though it's unlikely removal of a wrapper element would make the differerce keeping things consistent helps to mitigate issues

Feb 11, 2016 10:08


I understand your concerns but this is for a Block inside a block and the extra divs mess up the designers markup.

Feb 12, 2016 10:48
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.