Creating Content Types
Content types in Speck are created using the cf_spType, cf_spProperty and cf_spHandler tags. The cf_spProperty and cf_spHandler tags must be nested inside an opening and closing cf_spType tag and define the properties and methods for that type respectively. A single template is created for each type definition. The name of the type definition template must match the value of the name attribute of the cf_spType tag, the only required attribute. Speck creates a database table for each content type using the value of name attribute as the table name.
cf_spType tag syntax
<cf_spType
name = "type name"
caption = "caption to use in admin links etc."
description = "Short sentence describing type"
keywordFilter = "list of prefixes"
keywordTemplates = "list of templates"
revisioned = "yes|no"
keywordsRequired = "yes|no"
labelRequired = "yes|no"
extends = "parent type name"
final = "yes|no"
labelRoles = "list of roles and permissions"
keywordsRoles = "list of roles and
permissions"> <cf_spProperty ...>
<cf_spHandler ...>
</cf_spType>
The following table list the attributes of the cf_spType tag:
| Attribute | Type | Required | Description |
|---|---|---|---|
| Name | String | Yes | Type name, must match the template name. Note: Speck creates a database table using this value as the table name. |
| Caption | String | No | The caption to use when rendering admin links etc. Default is value of description attribute (for historical reasons). |
| Description | String | No | Short description for this content type. Default is the value of the name attribute. |
| KeywordFilter | List | No | Restrict keywords assigned to content items of this type to those beginning with one of the listed prefixes. Default "" |
| keywordTemplates | List | No | Restrict keywords assigned to content items of this type to those that represent a site section using one of the listed templates. Note: portal framework only, has no effect in standard Speck apps! |
| Revisioned | Boolean | No | Create new revisions of this type when revisioning is enabled. "No" used for content types that sit outside the revisioning / promotion process. Default yes |
| labelRequired | Boolean | No | Require label for each instance of this content type, default no. |
| LabelRoles | List | No | Use to specify read and write permissions for the label in the edit content form. See the access control section for more info. |
| keywordsRequired | Boolean | No | Require keywords for each instance of this content type, default no. |
| KeywordsRoles | List | No | Use to specify read and write permissions for the keywords in the edit content form. See the access control section for more info. |
| Extends | String | No | Name of parent content type. Currently, type inheritance is only supported for application content types extending server content types. The parent name given as the extends attribute must exactly match a server content type (i.e. a type definition template in /speck/types). |
| Final | Boolean | No | Prevent this type from being extended by other types, default no. |
The blurb content type, reproduced below, included with the standard Speck distribution is a simple example containing just one property and one method. Speck does not require you to write any more code to allow users to manage a content type, simply creating the type definition template and using the cf_spContent tag to output content of that type is enough.
Blurb content type definition
<cf_spType
name="Blurb"
description="HTML Blurb"
labelRequired="no">
<cf_spProperty
name="Blurb"
caption="Blurb"
type="Html"
required="yes"
displaySize="75,20"
maxlength="32000"
richEdit="yes"> <cf_spHandler
method="display">
<cfoutput>#content.blurb#</cfoutput>
</cf_spHandler> </cf_spType>
Properties
The cf_spProperty tag is used to define properties for a content type. The tag must be nested within opening and closing cf_spType tags. If you look at the definition of the blurb content type, it has just one property, also named blurb and the property type is Html.
The Html property type is one of a number of property types included with Speck that you can use in the creation of content types. It encapsulates the code required to handle html properties in speck, including how to render a html property in a form field, how to validate a new value for a html property before putting it into the database, any action to be taken when reading a html property form field, putting html into the database or even taking html out of the database.
It is the way that Speck property types encapsulate the code required to handle different types of data that makes the creation of content types such a simple process for developers.
cf_spProperty tag syntax
<cf_spProperty
name = "property name"
type = "Text|Html|Boolean|Asset|Picker|..."
caption = "Property caption used on edit form"
required = "yes|no"
requires = "list of properties required if this property has a
value" displaySize = "field display size"
maxLength = "max field size to save in characters"
style = "style to use on edit form"
class = "CSS class to use on edit form"
index = "yes|no"
roles = "list of roles and permissions"...
attributes particular to property type
>
The following table lists the attributes for the cf_spProperty tag:
| Attribute | Type | Required | Description |
|---|---|---|---|
| name | String | Yes | Property name. Note: If properties of this type are stored in the database (most are), speck creates a column in the type's table using this value as the column name. |
| type | String | Yes | The property type. Must match the name of a property handler template in the properties directory for the current application or the speck properties directory. |
| caption | String | Yes | Caption to use on edit form |
| hint | String | No | Additional hint to describe the property. When you use the hint attribute, a help icon appears beside the caption on the edit content form and when a user mouses over it, a tooltip containing the hint string appears. |
| required | Boolean | No | Property value required to save content? Default no |
| displaySize | String | No | Dimensions of edit control. For simple property types this is the length in characters, or "width,height" in characters for textarea-like controls. Other property types may have custom formats for this attribute. Default 50. If value is 0, the form field will be hidden. Hiding the form field is useful when users are not required to read or write the property value. For example, the image content type included with SpeckCMS contains properties to store the image dimensions. The content type includes a method to handle contentPut events, which calculates the dimensions and stores the resulting values in the corresponding properties when images are uploaded. As there is no need for the users to be aware that this information is even being stored, the displaySize attribute has been set to 0 for the properties that store the dimensions. |
| maxLength | Integer | No | Max length of content to allow in characters. Default 50. |
| requires | List | No | A list of the names of other properties that are required if this property has a value. |
| style | String | No | Style to use on edit form |
| class | String | No | CSS class to use on edit form |
| index | Boolean | No | Create index on database column. Default no. |
| finder | Boolean | No | Use this property as one of the search fields in the content finder (e.g. when searching for content items to reference from an existing content item using a Picker property). Default no. |
| roles | List | No | Use to specify read and write permissions for this property in the edit content form. See the access control section for more info. |
| unique | Boolean | No | Should this property value be unique for the content type. Default "no". If yes, a content item cannot be saved if the property value is already in use in another content item. IMPORTANT NOTE: The code that implements this attribute is only partially complete, with the result that when this attribute is used on sites with promotion enabled, property value uniqueness is forced at all revisions! |
Methods
Speck methods are blocks of code that display or otherwise manipulate content items of the content type in which they are defined. The example in the blurb content type above is about as simple a method as possible, it simply outputs the value of the blurb property of a particular content item. Methods are defined using the cf_spHandler tag, which must be nested inside opening and closing cf_spType tags and also must have a closing tag itself.
cf_spHandler tag syntax
<cf_spHandler method="name">
... method code
</cf_spHandler>
The following table lists the attributes for the cf_spHandler tag:
| Attribute | Type | Required | Description |
|---|---|---|---|
| Method | String | Yes | Name for the method being created |
The cf_spHandler tag sets up a content structure containing a key for each of the properties of the content item being process and a number of keys created by Speck containing other data relating to the content item. This structure is used by application developers to display property values and meta-data within content type methods. The display method in the Blurb content type above is a simple example, it outputs the value of the blurb property for the current content item being processed, i.e. content.blurb.
The following table lists the keys in the content structure that are created by Speck:
| Key | Description |
|---|---|
| spId | UUID of the content item |
| spType | Content type |
| spRevision | Revision number |
| spLabel | Label used by site administrators to identify content item |
| spCreated | Date content item (not just the current revision) created |
| spUpdated | Date last updated |
| spUpdatedBy | User who last saved content item |
| spKeywords | comma-separated list of content item keywords, sorted alphabetically ASC |
| spChangeId | Id of change object (if any) this revision is assigned to |
| spRowNumber | Current row number |