API Reference: AllowChildrenAttribute Class
The AllowChildrenAttribute
can be applied to content model classes. The attribute sets the content model types that may be used for child nodes of this content model in the node collection hierarchy. This allows you to restrict types within the site and asset library tree structure. This attribute together with the AllowAtRootAttribute
determine the type structure of a node collection hierarchy.
If AllowChildrenAttribute
is not specified on a content model class, no child nodes are allowed for this content model, effectively specifying that nodes of this content type are leaf nodes in the node collection tree.
Usage
Decorate the content model class with the AllowChildrenAttribute
. The attribute constructor accepts one or more Type
values as a params Type[]
parameter. Alternatively, the attribute can be set multiple times on the class.
If you want to allow any content type as children of this type, use the AllowChildrenAttribute
without any constructor parameters.
The attribute is not inherited, so any allowed child models that you have specified on a base class of this model will have to be specified explicitly on derived model classes.
Allowed child content types are only validated when creating or moving nodes in the back office. Changing the list of allowed child content types later has no effect on existing nodes.
Example
The following example specifies that a page of type Homepage
can only have child pages that are of type ContentPage
or NewsPage
.
[Page]
[AllowChildren(typeof(ContentPage), typeof(NewsPage))]
public class Homepage: IContentType
{
// ...
}
The following example specifies that a folder of type Folder
allows any other asset or folder type as its children.
[Folder]
[AllowChildren]
public class Folder: IContentType
{
// ...
}