Try our conversational search powered by Generative AI!

Restrict block types in contentarea



How can I restrict the block types that can be added to a contentarea?

Thanks in advanced,


Jeroen Slor

Nov 06, 2012 19:35

There is no easy way to block it in the UI. What you could do is write a custom validator for your typed model (page/block) that holds the contentarea. Below is an example on a validator implemenation that prevents users from adding a block of type "MyBlock" to the contentarea named "MainContentArea" on StandardPage.

public class StandardPageValidator : IValidate<StandardPage>
  public IEnumerable<ValidationError> Validate(StandardPage page)
     if (page.MainContentArea != null && page.MainContentArea.Contents.
     Any(c => c.GetOriginalType().IsAssignableFrom(typeof(MyBlock))))
        return new ValidationError[]{new ValidationError()
            ErrorMessage = "MyBlock is not allowed in this area",
            PropertyName = page.GetPropertyName<StandardPage>(p => p.MainContentArea),
            Severity = ValidationErrorSeverity.Error,
            ValidationType = ValidationErrorType.StorageValidation

       return Enumerable.Empty<ValidationError>();


The user experience will be that the editor will still be able to drop an instance of the block into the contentarea but when it is saved an message will appear saying tha the block is not allowed in the area. And it will not be possible to publish the change until the block is removed from the area.

Nov 07, 2012 8:09

Is it possible to limit which blocks that are available to choose from for specific users / groups?

Nov 07, 2012 8:33

You can for a shared block instance set access right on it in form edit mode (just like for pages). In admin mode/Set access rights you can also set access rights for folder (and pages/blocks)


Nov 07, 2012 8:42

I noticed something in the sample project.

In the SiteLogoTypeBlockControl.ascx this was specified:



AvailableWithoutTag =false,

Tags = new [] { "Header" })] // This block control is only allowed to be dropped in an area tagged with 'Header' through its RenderSettings property

And in the Site.Master the following:



<EPiServer:PropertyPageLink="<%#PageReference.StartPage %>"PropertyName="SiteLogotype"DisplayMissingMessage="True"runat="server">



 Doesn't that do what Jeroen asked about or have I misernderstood everything?

Nov 09, 2012 0:00

Yes that is another possible approach. With that approach it will be possible to drop the block in the area and it will be possible to save/publish the page. Then when rendered in edit mode a message will appear saying "There is no matching renderer for 'type'" and in view mode nothing will be rendered. 

Nov 09, 2012 5:26

I think a nice thing to have would be something like the possiblity to not show plugins via creating a null plugindescriptor.

This would be great both for all sorts of new stuff in 7 like blocks but also for gadgets.

The best thing would ofcourse be if it was possible to manage which gadgets, blocks, plugins etc thats available for specific users/groups  from admin mode. And that includes all the builtin gadgets etc not only the stuff we create ourselves.

Edited, Nov 09, 2012 8:41

Actually, as far as I see there is much easier way: decorate contentarea with         [AvailableContentTypes(Include = new[] { typeof(BlockType), })]

And customer would not be able to save a page, if there is wrong blocks added

Oct 22, 2013 18:04

Only classes can be decorated with AvailableContentTypes attribute.

You should use [AllowedTypes(typeof(...))] for your ContentArea property.

More info:

Edited, Feb 06, 2014 8:06

Valdis, the AllowedTypes comes in 7.5, this is a post in the 7 forum.

Feb 06, 2014 8:56

Oh, really. Then sorry - didn't look at version..

Feb 06, 2014 9:22

Maybe you can get this to Work?

Feb 21, 2014 7:51
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* 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.