Attributes and Their Type

Attributes and Their Type

Attribute definitions (sometimes called “fields” for historical reasons) can be added to an object class in order to customize the CMS objects (pages, widgets) based on it. To do this, just insert the attribute definition into the model class, like so:

Every attribute definition consists of a name and a type, the latter specifying the kind of data the corresponding attributes in the CMS objects accept. Attributes of the enum and multienum types also require values to make them functional (see the example above and the type descriptions below).

For further details, see Creating and Modifying Object Classes, Specifying Default Attribute Values. Creating a Page Type with Widgets also covers rendering.

Attribute types

Type Contents Function
binary Binary data A binary attribute is for storing the data of a resource, e.g. of an image. The value is either a freshly uploaded or an already existing blob.
When uploading a file to a field of this type, the file name may be composed of the following characters only: a-z, A-Z, 0-9, -, ~, _ and ..
date Date and time values A date attribute lets you store a UTC date and time value in the 14-digit format YYYYMMDDhhmmss.
enum Single-item selection list For optionally choosing a single value from a list of provided values. In attribute definitions, the available values are stored as an array of strings assigned to the values key. In a CMS object, the value of an enum attribute is the selected string value or an empty value.
float Number with fraction
All “double-precision 64-bit format IEEE 754” floating point values (see Java Floating Point and IEEE 754-1985 at Wikipedia for details) are supported, except (+/-) Infinity and NaN. The value of an empty float attribute is nil as a default (e.g. after creation) unless a custom default value has been specified.
html HTML text For regular text blocks. Other than with string attributes, HTML characters are not touched. Thus, the contents of html attributes is assumed to be valid HTML markup.
integer Number without fraction
An integer number in the range ±9007199254740991. See JavaScript Number.isSafeInteger() for details. The value of an empty integer attribute is nil as a default (e.g. after creation) unless a custom default value has been specified.
link Single link A link (Ruby API documentation) may point to a CMS object (internal link) or to an external web resource (external link). Every link has the following properties:

Property Details
title The link title can be used as the linked text in a “Related topics” list, for example. Use the display_title method if the URL of an external link or the title of the internal destination object should be used as a fallback.
obj For internal links, the destination CMS object. (A link can be either internal or external. Setting its obj removes its url and vice versa.)
query The URL query part of the link as in “index.html?query_string”.
fragment The URL fragment part (anchor) of the link as in “index.html#anchor”.
target The name of the window or frame in which the link destination should be opened (e.g. _blank or myname).
url The URL of an external link. url and obj are mutually exclusive.
linklist List of links A linklist attribute is a list represented as an array of link objects. See the link type above for the properties every link has. For examples, please refer to the API for CMS objects.
multienum Multi-item selection list This type is for choosing any number of values from a list of provided values. The values definition is the same as with enum attributes. In a CMS object, the value of a multienum attribute is the array of the selected string values.
reference CMS object ID The value of a reference attribute is the ID of an object in the working copy concerned. An attribute of this type can be used for connecting objects with another object in order to provide supplemental pieces of information such as an image or configuration data, for example. When a reference attribute is accessed in the Rails application, the Scrivito SDK conveniently returns the target object as an Obj instance, not the ID of the target object. If the target object does not exist, nil is returned.
referencelist List of CMS object IDs A referencelist attribute contains an array of CMS object IDs. Analogous to the reference type, the Scrivito SDK returns the target objects as an array of Obj instances. Nonexistent target objects do not show up in this array.
string Normal text Used for headlines, titles, paragraphs, etc. HTML characters are converted when rendered, for example < becomes &lt;, etc.
stringlist List of strings Can be used for keywords, extendable description lists, etc. The item order is preserved, duplicates are permitted.
widgetlist Collection of widgets An attribute of the widgetlist type acts as a container for widgets.