API Reference: EmbeddedAttribute Class
The EmbeddedAttribute
can be applied to content model properties. The attribute specifies that the content of a single-value nested content property will be embedded into its master content model, flattening and merging the properties list of the property model and the containing class in the back office user interface. This allows nested content to be presented as part of the content model in the user interface while keeping it a separate model class in code.
If EmbeddedAttribute
is not specified, the property will be rendered as a regular nested content item.
Usage
Decorate the content model property with the EmbeddedAttribute
. The attribute does not require any parameters. The attribute can only be set on single content model-based properties of a type that implements IContentType
. Setting it on any other property type will cause an invalid configuration exception on system startup.
Example
[Page]
public class ContentPage: IContentType
{
// SeoContent model properties will be rendered as if they were direct properties of the ContentPage model.
[Section("SEO")]
[Embedded]
public SeoContent Seo { get; set; }
// OtherContent model will be rendered as regular nested content view.
[Section("Content")]
public OtherContent Content { get; set; }
// This will throw an invalid configuration exception as collections can not be rendered as embedded.
[Embedded]
public ICollection<ModuleBase> Modules { get; set; }
// This will throw an invalid configuration exception as property types must be nested content models implementing IContentType.
[Embedded]
public string StringValue { get; set; }
}