Skip to content

Create a Content Type

⏱ 15 minutes beginner
📜Foundationcms

Content types define the structure of your content. Every page, block, and media item in CMS is an instance of a content type. When your site needs a new kind of content — a product page, an event listing, a testimonial — you create a new content type.

  1. Create a C# class that inherits from PageData, BlockData, or MediaData
  2. Add the [ContentType] attribute with a display name and GUID
  3. Add properties with display attributes
  4. Build and verify the type appears in the CMS editor
A basic page type
csharp
using EPiServer.Core;
using EPiServer.DataAnnotations;
using System.ComponentModel.DataAnnotations;

namespace MySite.Models
{
    [ContentType(
        DisplayName = "Event Page",
        GUID = "d1e2f3a4-b5c6-7890-abcd-ef1234567890",
        Description = "A page for upcoming events",
        GroupName = "Specialized")]
    [AvailableContentTypes(Include = new[] { typeof(EventPage) })]
    public class EventPage : PageData
    {
        [Display(Name = "Event Name", Order = 10)]
        [Required]
        public virtual string EventName { get; set; }

        [Display(Name = "Event Date", Order = 20)]
        [Required]
        public virtual DateTime EventDate { get; set; }

        [Display(Name = "Location", Order = 30)]
        public virtual string Location { get; set; }

        [Display(Name = "Description", Order = 40)]
        public virtual XhtmlString Description { get; set; }

        [Display(Name = "Registration Link", Order = 50)]
        public virtual Url RegistrationLink { get; set; }
    }
}

Key decisions:

  • GUID — Must be unique and never change after deployment. Generate one using Guid.NewGuid() or an online tool.
  • GroupName — Controls where the type appears in the “New page” dialog. Common groups: Content, Specialized, Containers.
  • AvailableContentTypes — Restricts which child page types can be created under this type.
A reusable block type
csharp
using EPiServer.Core;
using EPiServer.DataAnnotations;
using System.ComponentModel.DataAnnotations;

namespace MySite.Models
{
    [ContentType(
        DisplayName = "Testimonial",
        GUID = "e2f3a4b5-c6d7-8901-bcde-f23456789012",
        Description = "A customer testimonial with quote and attribution")]
    public class TestimonialBlock : BlockData
    {
        [Display(Name = "Quote", Order = 10)]
        [Required]
        public virtual string Quote { get; set; }

        [Display(Name = "Author Name", Order = 20)]
        public virtual string AuthorName { get; set; }

        [Display(Name = "Author Title", Order = 30)]
        public virtual string AuthorTitle { get; set; }

        [Display(Name = "Author Photo", Order = 40)]
        public virtual ContentReference AuthorPhoto { get; set; }
    }
}

Blocks inherit from BlockData instead of PageData. They do not have URLs — they are embedded within pages via ContentArea properties.

After building your project:

  1. Navigate to the CMS editor
  2. Right-click in the content tree and select “New page”
  3. Your new type should appear in the list, grouped by GroupName
  4. Create an instance and verify all properties appear in the editing form
IssueCauseFix
Type does not appear in editorMissing [ContentType] attributeEnsure the attribute is present with a valid GUID
Properties not showingMissing [Display] attributeAdd [Display] with Name and Order
Build error on propertyProperty not virtualAll CMS properties must be virtual
Duplicate GUID errorSame GUID used on two typesGenerate a new unique GUID