Content Type Anatomy

Håkan Edling edited this page Sep 20, 2018 · 8 revisions

Content types are the definition of how you want to structure your content. It should be structured in way so that it's easy accessible from your application code, but also so that it's easy to understand and maintain by the admin users of the CMS that will add new, and edit existing content. It's your responsibility when setting up this structure that you do it in a way that helps the website stay alive and current.

Content Types

Content Layout

The different Content Types in Piranha CMS are:

  • Pages
  • Posts
  • Sites

Content Type Components

When defining and working with content you have access to the following components.

  • Fields
  • Regions
  • Blocks

Below you can read more about different components available.

Fields

Fields are the lowest level of content in Piranha CMS and are used to build up Regions and Blocks. You can think of Fields as the different data types that you can use to build structures with. When defining a field in your Region or Block you can set the following properties with the FieldAttribute.

Title

Optional title to be shown in the manager interface. If this property is left empty the property name is used.

public class MyRegion
{
    [Field(Title = "The Title")]
    public StringField Title { get; set; }
    [Field]
    public TextField Body { get; set; }
}

Options

A set of flags defining additional field behavior. At the moment the only flag available is HalfWidth which tells the manager interface that the field should only take up 50% of the available space so that another field can be display next to it.

public class MyRegion
{
    [Field(Options = FieldOption.HalfWidth)]
    public StringField Title { get; set; }
    [Field(Options = FieldOption.HalfWidth)]
    public StringField SubTitle { get; set; }
    [Field]
    public TextField Body { get; set; }
}

For a complete description of the available field types, please refer to Field Types.

Regions

Regions should be used for fixed occurrences of data on a Content Type, for example a Banner that always appear on the top for a Content Type. For content that can be placed at any position and occur any number of times Blocks are better.

Regions are the top-most level you can use to structure the different pieces of content that makes up a page. They are very flexible and can be configured in several ways, for example:

  • A single field region - for main content regions
  • A composite region made up of several fields
  • A sortable collection of both of the above.

Single Field Regions

When defining single field regions, the field type must be referenced directly from the Content Model. The deserializer does not support custom objects with a single field.

Correct Implementation

[PageType]
public class MyPage : Page<MyPage>
{
    [Region]
    public HtmlField Body { get; set; }
}

Incorrect Implementation

public class MyBody
{
    [Field]
    public HtmlField Body { get; set; }
}

public class MyPage : Page<MyPage>
{
    [Region]
    public MyBody HtmlBody { get; set; }
}

The preferred way to define you content types is to use the package Piranha.AttributeBuilder which lets you use attributes to markup your models with. The region attribute has the following Properties.

Title

Optional title to be shown in the manager interface. If this property is left empty the property name is used. The example below shows a single field region in a Content Type.

[Region(Title = "Main content")]
public MarkdownField MainContent { get; set; }

ListTitle

The optional field name of a composite region that should be used when rendering the collapsed list items in the manager interface. The example below shows a composite region that is made up of a StringField and a TextField.

public class MyRegion
{
    [Field]
    public StringField Title { get; set; }
    [Field]
    public TextField Body { get; set; }
}

...

[Region(ListTitle = "Title")]
public IList<MyRegion> Teasers { get; set; }

ListPlaceholder

Optional text to show when a new list item has been created until it's been saved.

[Region(ListTitle = "Title", ListPlaceholder = "New Teaser")]
public IList<MyRegion> Teaser { get; set; }

ListExpand

If the list item should be expandable or if the fields should be shown directly in the list. The default behavior is true but it can be useful to set it to false if you have a single field region or a very simple list region. The example below will create a list of image fields and show them directly in the list.

[Region(ListExpand = false)]
public IList<ImageField> Images { get; set; }

SortOrder

Optional sort order. This can be useful if you want to inherit a base class containing regions and you want to force them into being displayed in a certain way in the manager interface. The default sort order is in the order they are declared in the class.

Blocks

Blocks should be used for pieces of content that can occur any number of times, at any position in the main content of a Content Type. For fixed elements with a fixed number of occurrences Regions are a better match.

Blocks are defined in the same way as regions with the exception that they must inherit from Piranha.Extend.Block. Block Types are also registered in the Application Startup. Blocks can't be used when designing your Content Type, instead they are content pieces that the Content Administrators can use when designing the content of the pages.

Here is an example of the basic single column HTML block included in Piranha:

/// <summary>
/// Single column HTML block.
/// </summary>
[BlockType(Name = "One Col", Category = "Content", Icon = "fab fa-html5")]
public class HtmlBlock : Piranha.Extend.Block
{
    /// <summary>
    /// Gets/sets the HTML body.
    /// </summary>
    public HtmlField Body { get; set; }
}
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.