How to create a Content Type

From Sense/Net Wiki
Jump to: navigation, search
  • 100%
  • 6.0
  • Enterprise
  • Community
  • Planned


Content types define the structure of content:

A Content Type Definition is an XML-format configuration file for types. After creating a new Content Type Definition new content of the created type are immediately available in the system and can be created and used. The XML configuration (CTD) holds information about

  • the content's name, description, default icon
  • parent content type
  • fields (name, title and configuration of fields)

In case default logic is not adequate and defining custom programmed logic is necessary a Content Handler for the type can be implemented in C# and the compiled library placed in the web folder's bin directory. Attached business logic can also be added by implementing custom Fields and custom Field Controls.


In this section I will show you how to create a new Content Type step-by-step. To demonstrate the type definition capabilities of Sense/Net I will create a new Movie type that can be used to build movie data bases.

1. Login and go to Explore

The user must have administrator privileges - you may use the admin user with the default install. Explore is a management surface of the portal where you can navigate through the Content Repository and manage content. Start Explore by clicking on the Explore link in the Portal Remote Control, the floating black panel on the main page visible to administrators!

2. Navigate to ContentTypes folder and click New

  • Using the tree on the left side of Explore page navigate to /Root/System/Schema/ContentTypes folder
Exploring ContentTypes folder
  • In the list grid on the right side click on the New link.

This is where we will type in the Content Type Definition XML of our new type.

3. Insert Content Type Definition XML and click Install

Our new Movie type will have the following features:

  • holds basic information of the movie (title, year, director, plot outline)
  • holds an image of the movie poster

The Content Type Definition for the Movie type will look something like this:

<ContentType name="Movie" parentType="GenericContent" handler="SenseNet.ContentRepository.GenericContent" 
  <Description>A simple movie type to build movie databases</Description>
    <Field name="Title" type="ShortText">
      <Description>Title of the movie</Description>
    <Field name="Year" type="Integer">
      <Description>Year of release date</Description>
    <Field name="Director" type="ShortText">
      <Description>Name of director</Description>
    <Field name="Plot" type="LongText">
      <Description>Plot outline</Description>
    <Field name="ImageRef" type="Reference">
      <DisplayName>Poster image (reference)</DisplayName>
    <Field name="ImageData" type="Binary">
      <DisplayName>Poster image (binarydata)</DisplayName>
    <Field name="Image" type="Image">
      <DisplayName>Poster image</DisplayName>
      <Bind property='ImageRef' />
      <Bind property='ImageData' />

Let's go through the xml very quickly. There are some basic properties defined on the root element:

The main structure of the xml contains the following elements:

  • Title: the displayed name of the type
  • Description: the description of the type
  • Icon: default icon for the type. Our Movie type will use the basic Content icon (upload custom icons to the /Root/Global/images/icons folder)
  • Fields: this element is the container of field definitions

The following fields are defined in the Fields section:

  • Title: the title of the movie. This field is already defined on the parent Content Type (GenericContent) since every content has a displayed name. For a movie this is the title of the movie so we override the parent's Title field and redefine the title and description of the field
  • Year: movie release date. Year info is adequate so we use a simple IntegerField field for this
  • Director: the name of the director of the movie. A simple ShortTextField field is used
  • Plot: we use a LongTextField field to contain the plot outline. Note that we indicated that the field is displayed with a RichText control instead of the default LongText field control
  • ImageRef: a technical field for the poster image
  • ImageData: a technical field for the poster image
  • Image: field for the poster image (uses ImageRef and ImageData technical fields referred in the Bind element)

You can go ahead - paste the xml into the content type editor box and click Install.

4. Use the created type

After installing the new Content Type Definition and refreshing the ContentTypes folder you should see the Movie type appeared under the Content type:

New Movie Content Type

Now you can create new Movie content and manage them just like any other content. Stay in Explore mode, go to Default Site and click on New in the grid. In the appearing screen select Movie from the dropdown:

Creating a movie content

The edit ContentView of the type with the defined fields appears:

Creating a movie content

5. Modifying a Content Type Definition

You can view and edit the Content Type Definition of your type simply by navigating to the Content Type in Explore. A surface is provided with child Content Types, field information and available actions:

To edit the CTD click on the Edit link and the Content Type editor will appear. Click Install to save changes to the CTD.


Related links