Please help us by completing this survey

Go to survey
Tutorials

Docs / Tutorials / How to create a Content Type

How to create a Content Type

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

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.

Steps

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

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:

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

<ContentType name="Movie" parentType="GenericContent" handler="SenseNet.ContentRepository.GenericContent" 
xmlns="http://schemas.sensenet.com/SenseNet/ContentRepository/ContentTypeDefinition">
  <DisplayName>Movie</DisplayName>
  <Description>A simple movie type to build movie databases</Description>
  <Icon>Content</Icon>
  <Fields>
    <Field name="Title" type="ShortText">
      <DisplayName>Title</DisplayName>
      <Description>Title of the movie</Description>
    </Field>
    <Field name="Year" type="Integer">
      <DisplayName>Year</DisplayName>
      <Description>Year of release date</Description>
    </Field>
    <Field name="Director" type="ShortText">
      <DisplayName>Director</DisplayName>
      <Description>Name of director</Description>
    </Field>
    <Field name="Plot" type="LongText">
      <DisplayName>Plot</DisplayName>
      <Description>Plot outline</Description>
      <Configuration>
        <ControlHint>sn:RichText</ControlHint>
      </Configuration>
    </Field>
    <Field name="ImageRef" type="Reference">
      <DisplayName>Poster image (reference)</DisplayName>
      <Configuration>
        <VisibleBrowse>Hide</VisibleBrowse>
        <VisibleEdit>Hide</VisibleEdit>
        <VisibleNew>Hide</VisibleNew>
        <AllowMultiple>false</AllowMultiple>
      </Configuration>
    </Field>
    <Field name="ImageData" type="Binary">
      <DisplayName>Poster image (binarydata)</DisplayName>
      <Configuration>
        <VisibleBrowse>Hide</VisibleBrowse>
        <VisibleEdit>Hide</VisibleEdit>
        <VisibleNew>Hide</VisibleNew>
      </Configuration>
    </Field>
    <Field name="Image" type="Image">
      <DisplayName>Poster image</DisplayName>
      <Bind property='ImageRef' />
      <Bind property='ImageData' />
    </Field>    
  </Fields>
</ContentType>

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:

The following fields are defined in the Fields section:

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:

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:

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

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.

Is something missing? See something that needs fixing? Propose a change here.