N2CMS

A glance at our domain model

Okay, let's dive right in and look how a what a simple project would look like in Visual Studio. That's where most of the development effort is spent when developing an N2 CMS.

An important concept in N2 is the content item class. This is the definition of a certain kind of page in our CMS. Instances of this class (objects) contain the content/data that we want to display using a template (an aspx page). 

N2 allows you to define which types of content items are available in your CMS by creating .NET classes and decorating them with attributes. If you want you can develop diverse functionality without creating any database tables or building any imput forms.

The content bearing class (content item)

  • In N2 types of content are defined through classes deriving from N2.ContentItem. These classes have properties (e.g. the Text string) that expose the actual content.
  • Since TextPage inherits from N2.ContentItem (in this case a bit down the inheritance chain) it is treated by the N2 engine as a content type and made available for editing through the edit interface.
  • Take a quick look at that Text property before you move on. It has an interesting attribute that's used by the N2 engine to determine what kind of editor should be used to edit that property.

A property encapsulating our content

  • First, lets examine that attribute called EditableFreeTextArea. The attribute tells the N2 engine that this is a property that is editable in edit mode. Since it's the EditableFreeTextArea attribute a textarea is displayed when you edit this page. The parameters are just the name displayed in edit and the order of this property. Available options:
    • EditableTextBox - simple text input
    • EditableFreeTextArea - tinyMCE WYSIWYG editor
    • Editable - specifically define a which control to perform the editing
    • Create subclass that overrides the GetEditor method and returns a control loaded as needed.
  • Secondly, look at that GetDetail call in the getter. GetDetail gets values from a content detail collection and SetDetail updates the same value. Any serializable class is supported. The content detail collection contains all custom properties.