Search code examples
n2cmsn2

N2CMS: restricting the number of ContentItems of a certain type below another ContentItem


I'm using N2CMS, and I have two classes that inherit from ContentItem - say HomePage and NewsPage. NewsPage is set to only appear under HomePage (using the RestrictParents attribute):

[RestrictParents(typeof(HomePage))]

Can I make it so there is a maximum number of NewsPages (in this case 1) below the home page?


Solution

  • The answer is that you can use the

    [RestrictCardinality] 
    

    attribute. In the example I gave in the question, you would use

    [RestrictCardinality(ComparableType=typeof(NewsPart), MaximumCount=1)]