CMS Objects, Widgets, and Classes 

CMS Objects, Widgets, and Classes 

What are CMS objects?

Every unique piece of content (with the exception of widgets) is a CMS object, e.g. a page, an image, video, PDF document, etc. Scrivito stores all content produced or uploaded by editors in CMS objects. A CMS object not necessarily represents or holds all the static content of a particular web page. It might, but it might also merely be used as a place where special-purpose content, e.g. a teaser image or contact information is kept.

In the Scrivito SDK, CMS objects are represented by the “Obj” model class. Further object classes can be derived from “Obj” to make specific page types available and provide them with custom attributes.

Built-in and custom attributes

All objects have a couple of built-in attributes. Their ID, for example, makes CMS objects unique, permalinks are good for SEO and for better remembering page URLs. For hierarchically organized content, the path of an object optionally specifies its location in the object hierarchy, analogous to the path of a file in a file system.

In addition to these built-in attributes, objects may be given custom attributes for storing the pieces of information the objects require to function as intended. The custom attributes of a CMS object represent the “slots” in which content or metadata can be stored and from which these pieces of information can be obtained to render web pages.

There are several attribute types available for specifying the kind of content meant to be stored in a custom attribute. “string” attributes, for example, are for usual text, while “html” attributes accommodate HTML markup. The “date” type is dedicated to date and time information, “referencelist” is specialized in collecting CMS objects, e.g. for manually maintaining navigations.

The “widgetlist” attribute type is the most important one. It allows editors to conveniently create and freely arrange page content using pre-built widgets.

Object classes for structuring the website

“Obj”, the parent class of all CMS object classes, includes various methods for structuring a website and maintaining its structure. The “valid_page_classes_beneath" method, for example, is a callback for restricting the use of particular page types to the website areas in which they make sense. “Obj” also includes several methods for locating CMS objects, e.g. “find_by_path", or “where."

Object classes can be hidden to prevent unique (special purpose) pages, e.g. the homepage, the error page, or the log-in page, from being created more than once.

Widget classes for structuring pages

Analogously to object classes, widget classes let you create widget types for the individual kinds of content editors want to place on pages. All widget classes are based on subclasses of “Widget.” As with CMS objects, the content of a widget is stored in its attributes.

See Providing Page and Widget Views for more on how object and widget classes are manifested in a Rails application.

Scrivito offers Rake tasks for creating page and widget models as well as the views that render their instances. There's a guide on how to create a page type with widgets for you to get started.