Content types

The 'C' in CMS means "content" so it would be fair to say that content is anything that the CMS manages. More precisely, content is everything in the site that has any information in it. For example, a page, a blog post, a comment, a product or your company's logo are identifiable individual pieces of content, i.e. content items.

Content items are instances of content types. Said differently, content types are classes of content items. We said in the previous section that examples of content items are pages, blog posts, and products. Those three examples also describe three content types: page, blog post and product. In other words what we call a blog post is just an item of type blog post.

There are a number of built in content types that you can use as building blocks when creating your site. However, you would normally create at least some custom content types that map to your specific needs.

The anatomy of Lemoon content types

A content type is a class that inherits from the Mindroute.Core.Model.Content class or from a class that in turn inherites from that class. The Mindroute.Core.Model.Content class defines all common fields like Title, Permalink, CreatedBy etc. etc.

Content types are created as normal classes directly in your project or referenced from a separate project or class library. When a Lemoon application starts up it will automatically find all referenced extensions including content types.

Content types are composed of a number of fields. These can be decorated with attributes that describe how the field should be displayed and edited.

Examples

Most of the examples are taken from the default project template.

using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Mindroute.Core.Helpers;
using Mindroute.Core.Model;
 
namespace MyProject.Lemoon.ContentTypes {
 
    [Serializable]
    [Render(Name = "Start page", Description = "Start page with optional modules.")]
    [DefaultValues("IsSearchable", true, "DisplayInMenu", DisplayInMenu.Always, "IsEnabled", true, "Template", "~/Lemoon/Templates/StartPageTemplate.aspx", "AllowedChildren", new string[] { "Mindroute.Core.Model.Content" })]
    public class StartPage : Content {
 
        private string _facebookurl;
        private string _twitterurl;
        private string _feedurl;
 
        /// <summary>
        /// Gets or sets the body text of the start page.
        /// </summary>
        [Persisted]
        [DataType(DataType.Html)]
        public string Body { get; set; }
 
        /// <summary>
        /// Gets or sets a list of modules to display on the start page.
        /// </summary>
        [Persisted]
        [DataType("Pages")]
        public List<ContentRef> Modules { get; set; }
 
        /// <summary>
        /// Gets or sets the about text displayed in the footer.
        /// </summary>
        [Persisted]
        [DataType(DataType.Html)]
        [Layout(Height = "200px")]
        public string About { get; set; }
 
        /// <summary>
        /// Gets or sets the copyright text displayed in the footer.
        /// </summary>
        [Persisted]
        public string Copyright { get; set; }
 
        /// <summary>
        /// Gets or sets the address displayed in the footer.
        /// </summary>
        [Persisted]
        [DataType(DataType.MultilineText)]
        [Layout(Height = "100px")]
        public string Address { get; set; }
 
        /// <summary>
        /// Gets or sets the contact info displayed in the footer.
        /// </summary>
        [Persisted]
        [DataType(DataType.MultilineText)]
        [Layout(Height = "100px")]
        public string Contact { get; set; }
 
        /// <summary>
        /// Gets or sets a link to a facebook page.
        /// </summary>
        [Persisted]
        [DataType(DataType.Url)]
        [Render(Name = "Facebook Url")]
        public string FacebookUrl {
            get {
                return _facebookurl.FixUrlWithoutProtocol();
            }
            set {
                _facebookurl = value;
            }
        }
 
        /// <summary>
        /// Gets or sets a link to a twitter account.
        /// </summary>
        [Persisted]
        [DataType(DataType.Url)]
        [Render(Name = "Twitter Url")]
        public string TwitterUrl {
            get {
                return _twitterurl.FixUrlWithoutProtocol();
            }
            set {
                _twitterurl = value;
            }
        }
 
        /// <summary>
        /// Gets or sets a link to the main feed of the site.
        /// </summary>
        [Persisted]
        [DataType(DataType.Url)]
        [Render(Name = "Feed Url", Description = "Link to the main rss or atom-feed of the site.")]
        public string FeedUrl {
            get {
                return _feedurl.FixUrlWithoutProtocol();
            }
            set {
                _feedurl = value;
            }
        }
    }
}

Example 1: Startpage.cs. Various properties for content and selectors.

using System;
using System.ComponentModel.DataAnnotations;
using Mindroute.Core.Model;
 
namespace MyProject.Lemoon.ContentTypes {
 
    [Serializable]
    [Render(Name = "Module", Description = "Module to be displayed on the start page.")]
    [DefaultValues("IsRoutable", false, "IsSearchable", false, "DisplayInMenu", DisplayInMenu.Admin, "IsEnabled", true)]
    public class Module : Content {
 
        [Persisted]
        [DataType(DataType.Html)]
        public string Body { get; set; }
 
        [Persisted]
        public ContentRef Link { get; set; }
 
    }
}

Example 2: A module (spot) that contains a html field and a reference to a different page.

using System;
using Mindroute.Core.Model;
 
namespace MyProject.Lemoon.ContentTypes {
 
    [Serializable]
    [Render(Name = "Container", Description = "Used as a container for modules etc.")]
    [DefaultValues("IsRoutable", false, "IsSearchable", false, "DisplayInMenu", DisplayInMenu.Admin, "IsEnabled", true, "AllowedChildren", new string[] { "Mindroute.Core.Model.Content" })]
    public class Container : Content {
 
    }
}

Example 3: Container.cs. A content type without any properties used for building structure. Will never be served publicly (not routable).

using System;
using Mindroute.Core.Model;
using System.ComponentModel.DataAnnotations;
 
namespace MyProject.Lemoon.ContentTypes {
 
    [Serializable]
    [Render(Name = "Example")]
    [DefaultValues("DisplayInMenu", DisplayInMenu.Always, "IsEnabled", true)]
    public class Example : Content {
 
        [Persisted]
        [Range(1, 10)]
        public int IntValue { get; set; }
 
        [Persisted]
        [StringLength(10)]
        public string StringValue { get; set; }
 
 
    }
}

Example 4: Example content type with some validation. The IntValue property has a range attribute restricting the input to a number between 1 and 10. The StringValue property has a string length attribute limiting the input to 10 characters.