Nested Content

Nested content are content models that are part of another content model. Nested content can be multiple levels deep.

Example

Below is an example of a typical frequently asked questions (FAQ) nested content structure. The FAQ content has a heading and section collection, and each section has a name and collection of FAQ items. The Faq content model can itself be put on a page model, or used in a content library as a shared (reuseable) item.

public class Faq: IContentModel
{
    public string Heading { get; set; }

    [MaxContent(10)]
    public List<FaqSection> Sections { get; set; }
}

public class FaqSection: IContentModel
{
    [Required]
    public string Name { get; set; }

    public List<FaqItem> Items { get; set; }
}

public class FaqItem: IContentModel
{
    [Required]
    public string Question { get; set; }

    [Required]
    [Multiline]
    public string Answer { get; set; }
}

Allowed content models

In the example above, both collections (List<FaqSection> Sections and List<FaqItem> Items) are of a specific generic type. This means that only those content models can be added to the collection. It is also possible to specify a collection of a base type, or even only the base IContentModel interface. In that case, you need to decorate the property with AllowContentModelAttribute to specify which content models are allowed to be added to the collection. The user will be then presented with a list of allowed content models when adding a new item to the collection in the back office.

public class ContentPage: IPageModel
{
    [AllowContentModel(typeof(Paragraph), typeof(Faq), typeof(Slider))]
    public List<IContentModel> Modules { get; set; }
}

In this example, the Modules property on the ContentPage page model will appear in its own section in the user interface. The allowed content models must implement the IContentModel interface. When the user adds new content to the modules section, one of the 3 allowed content models must be selected from the list.