volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

volume_up

A critical vulnerability was discovered in React Server Components (Next.js). Our systems remain protected but we advise to update packages to newest version. Learn More

Limit blocks in ContentArea

Hi guys,

What would be the best way limit the number of blocks allowed to be placed inside a ContentArea? Would this need to be a custom control or is there a way to limit this in the admin system?

I'm quite new to EPiServer, so if someone has some example code, that would be fabulous :-)

Cheers,
Chris

#76475
Oct 25, 2013 12:59

You could add a validator. See an example for ContentAreas in this thread:

 

http://world.episerver.com/Modules/Forum/Pages/thread.aspx?id=63002

This example validates the type of Content but you could easily change it to number of Blocks

#76477
Oct 25, 2013 13:15

Thanks Alf. That seems like it could work!

How would I keep track of how many blocks there are in the ContentArea, using that example as a starter?

#76485
Oct 25, 2013 15:02
Vote:

You can look at the ContentArea.Contents for each Content/Block/Page added.

Use Linq methods such as .Count() to find out the amount.

If you want to re-use this validation on several Page Types, you can create a separate validator.

 

See more at http://world.episerver.com/Blogs/Alexander-Haneng/Dates/2013/1/Limiting-a-Page-Property-to-a-specific-Page-Type-in-EPiServer-7/

The value should be parsed to ContentArea instead of PageReference as is used in the example.

#76486
Oct 25, 2013 15:08

Thanks Alf, I'll check it out :-)

#76488
Oct 25, 2013 16:23

Is this still the best solution as of EPiServer 8?

#121464
May 11, 2015 18:48
error 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.