Defining Content Types
The temp-dev
content items discussed earlier have
three fields: title, summary
and body. These fields are defined in the content
item's content-type
definition.
Look at one of the temp-dev
content items in
Content Studio.
Click on the Properties
tab in the article editor
to display general information about the article. You will see that
its Content type is set to
Story:
If you select File > New from the menu bar you will see that the displayed submenu contains a Story option. If you select this option, a new content item is created and opened in an editor tab. The editor tab contains the same three fields: Title, Summary and Body.
Now go to your application server's web applications folder, then find
and open
temp-dev/META-INF/escenic/publication-resources/escenic/content-type
in a text editor. Search for the string "Story" and you should find
the following definition:
<content-type name="news"> <ui:label>Story</ui:label> <ui:description>A news story</ui:description> <ui:title-field>title</ui:title-field> <panel name="default"> <ui:label>Main Content</ui:label> <ui:description>The main content fields</ui:description> <ref-field-group name="title"/> <ref-field-group name="summary"/> <ref-field-group name="body"/> </panel> <ref-relation-type-group name="attachments"/> <summary> <ui:label>Content Summary</ui:label> <field name="title" type="basic" mime-type="text/plain"/> <field name="summary" type="basic" mime-type="text/plain"/> </summary> </content-type>
This code defines a content type called "news" with the following characteristics:
-
The
label
"Story". This is the name that is used wherever it appears in Content Studio. -
A
Panel
with thename
"default" and thelabel
"Main Content". If you look in Content Studio you will see that the article fields are all displayed on a tab card called Main Content. -
References to three field groups called
title
,summary
andbody
. -
Other characteristics we will look at later.
Immediately above the "news" element, you should find the definitions of the referenced field groups:
<field-group name="title"> <field mime-type="text/plain" type="basic" name="title"> <ui:label>Title</ui:label> <ui:description>The title of the article</ui:description> <constraints> <required>true</required> </constraints> </field> </field-group> <field-group name="summary"> <field mime-type="text/plain" type="basic" name="summary"> <ui:label>Summary</ui:label> <ui:description>The summary text of the article.</ui:description> </field> </field-group> <field-group name="body"> <field mime-type="application/xhtml+xml" type="basic" name="body"> <ui:label>Body</ui:label> <ui:description>The body text of the article.</ui:description> </field> </field-group>
As you can see, each field group contains the definition of a single field with the same name as the group, and they define the fields displayed on the Main Content tab in Content Studio.
The following example shows the definition of a new content type
called "review", intended to be used for review articles. Try adding
it to the content-type
resource after the existing
"news" content type.
<content-type name="review"> <ui:label>Review</ui:label> <ui:description>A product review</ui:description> <ui:title-field>title</ui:title-field> <panel name="default"> <ui:label>Main Content</ui:label> <ui:description>The main content fields</ui:description> <ref-field-group name="title"/> <ref-field-group name="summary"/> <ref-field-group name="body"/> <ref-field-group name="review"/> </panel> <ref-relation-type-group name="attachments"/> <summary> <ui:label>Content Summary</ui:label> <field name="title" type="basic" mime-type="text/plain"/> <field name="summary" type="basic" mime-type="text/plain"/> </summary> </content-type>
It is, as you will see, very similar to the original "news" content type definition. Apart from the name and label, the only significant difference is the addition of a fourth field group called "review".
In order for this new content type to work, therefore, we must also add a definition for the new field group it refers to:
<field-group name="review"> <field type="enumeration" name="review-type"> <ui:label>Review Type</ui:label> <ui:description>Select the required type</ui:description> <enumeration value="film"/> <enumeration value="play"/> <enumeration value="book"/> <enumeration value="game"/> </field> <field type="number" name="score"> <ui:label>Score</ui:label> <ui:description>Enter your rating</ui:description> <constraints> <minimum>1</minimum> <maximum>6</maximum> </constraints> </field> </field-group>
This field group, unlike the other field groups in the
content-type
file, contains more than one field.
Field groups, however, have no effect on the layout of the fields in
Content Studio
or on how fields are accessed from templates. You can use them to
group fields in whatever way is most convenient.
The fields in this group are of a different type from the fields we have seen so far:
-
The
review-type
field is of typeenumeration
, and contains a list of alternative values. -
The
score
field is of typenumber
and contains aconstraints
element that specifies the allowed range for the field.
After making these changes to content-type
, upload
the new resource as described in
Creating/Updating Publication Resources.
Then restart
Content Studio.
Select File > New from
the men bar: you will see that the displayed submenu now contains a
Review option, which you can select to create a
review
content item. The editor displayed contains
the new fields you have defined:
-
Review Type is displayed as a combo box containing the options you specified.
-
Score will only let you enter a value in the range 1-6. If you enter a value outside this range, then the field title turns red to indicate that the value is invalid.
There are many other field types you can select from. For more information about field types, see More About Defining Fields. For a complete list of available field types, see here.