The first content class

Now that we've included the required files in the solution and configured web.config it's time to create a content item class, i.e. a class of objects that will contain the information to display with the site.

The included editing interface will make it easy for web content editors to create and organize instances of the content class.

Setting up references 

First we need to set up some references. A good idea is keeping a folder with the referenced dll:s e.g. like this.

The references folder

Now we set up a reference to the n2.dll file:

Referencing N2.dll

 

Creating a content item class 

Creating the class

Creating the class

Inheriting N2.ContentItem

The base class you need to inherit in order to benefit from the services of N2 is N2.ContentItem. This class has a few basic properties, give the item a location in a hierarchical item structure and provides a property bag where we can store all kinds of data. The purpose of the class is to provide the basic foundation needed to store content.

Inheriting N2.ContentItem

Defining class title and discriminator

The title is used to identify this class of items in the edior interface.The second parameter is a discriminator. If you change the class name later on you can use this string to map existing content to the new class. Update: the attribute is now renamed to [Definition].

Adding a title and a discriminator

Using the n2 property snippet

The n2prop snippet creates a property that stores data in the property bag and defines a text box to edit that data. 

Using the n2 property snippet

This is how the snippet expands. By default a textbox is used to edit the property. The data is stored in the property bag called Details with the utility methods GetDetail and SetDetail.

Using the n2 property snippet

Changing title and property name

Now we've changed the label displayed with the textbox to Text and also changed the name of the property to "Text". 

Changing title and property name

Changing to the free text area

Since we want to provide some nicer options when editing this property change the Editable attribute to EditableFreeTextArea. This allows us to edit the text with a WYSIWYG editor. There are several other editables and it's possible to implement your own editable attributes.

Changing to the free text area

Defining a title editor

In most situations you'll want to edit the title of the page. Since Title is a property available in the base class we can use a predefined attribute on the class: WithEditableTitle

Defining an editable title