Limit blocks in ContentArea

Vote:
 

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
Vote:
 

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
Vote:
 

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
Vote:
 

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

#76488
Oct 25, 2013 16:23
Vote:
 

Is this still the best solution as of EPiServer 8?

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