Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Restrict a block type to only be created on a specific page type and in a specific contentarea


I'm trying to restrict a block to only be allowed to be created on a specific page type, in a specific contentarea on that page type. Is this possible? If not both, then perhaps restricting to a certain page type is possible?

I know it's possible to set which block types are allowed in a contentarea, but i don't want to go around changing settings for every single contentarea to restrict this one block type. Also using IValidate seems to be an option, but i would like to avoid using it. For the user experience it would be better not to show the block type at all where it's not supposed to be created.

Thanks a lot!

Mar 02, 2020 21:36

Hi Robert

The block can be created from different places in the CMS UI. E.g. block widget or content area directly. Therefore, I think you have to implement restriction in you code from preventing Editor accidently drags unwanted blocks into the content area regardless. 

It depends on what you're after. If you want to filter the list of available blocks for content area or specific site, it is doable. 

Mar 02, 2020 23:48

Can this blocktype be used multiple times on that page? If not, you could make it a property on the page and hide the block from editors to be used in content areas

Mar 03, 2020 8:49
Robert Danielsson - Mar 03, 2020 9:09
I should've mentioned this, i need multiple blocks of that type in the contentarea. I thought of using it as a prop, but perhaps that only works with a singular block? Or would a List of that block type work?

Hi Robert,

I've had something similar before.

You can set the block as 'AvailableInEditMode = false' and then set the allowed types for your content area to that block.

The next part is a bit of a compromise...

Last I checked, the ContentArea won't have a link for you to create the block, nor can you create one in the sidebar (due to the availability) HOWEVER, if you add an instance of the block by default (programmatically, using code), then you'll get the link in the content area for adding more.

Hopefully, this helps get you part of the way there...


- JJ

Mar 03, 2020 10:03
Robert Danielsson - Mar 03, 2020 18:59
Thank you, this might work as a solution. I'll try it out! I'm surprised this feature doesn't seem to exist and even more confused that i'm barely getting any hits on google about this.
James Johnson - Mar 05, 2020 8:46
Same. I reported the lack of the link as a bug, as to me, it made sense to be able to restrict a block that way. They weren't having any of it though and there is a better solution, I've not come across it.

I think, technically, you're meant to be able to IncludeOn, or something like that, but from my experiments, it very rarely worked as you would expect it to... :/
* 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.