createObjClass(options)

Creates a page or resource type for the CMS, without adding it to the registry of CMS object types.

Scrivito.createObjClass generates an object class using the given schema.

Object classes serve as boilerplates for CMS objects. Their main purpose is to define the attributes the instances require, for example a string attribute named "title" or a binary attribute for binary data like an image or a PDF document.

Copy
const LandingPage = Scrivito.createObjClass({
  attributes: {
    title: 'string',
    body: 'widgetlist',
  },
});

Please note that Scrivito.createObjClass does not automatically add the generated class to the registry of CMS object types. Instead, it is considered an „abstract class“. An abstract class is useful:

  • as a superclass for specialized CMS page types and resources,
  • for overloading an API method (e. g. slug) before registering the final type using Scrivito.provideObjClass.

Options

  • attributes (Object) – The attribute definition of the CMS object class. Either only the type, or an array consisting of the type, followed by options. Available options are:
    • values (Array) – List of values that can be assigned (applies to the enum and multienum types).
    • only (String or Array) –
      • With widgetlist attributes, optionally the name of a widget class (String) or a list of such names (Array). If specified, only widgets of the given class(es) can be placed into the widgetlist attribute.
      • With reference and referencelist attributes, optionally the name of an object class (String) or a list of such names (Array). If specified, only CMS objects of the given class(es) can be placed into the attribute.
    • extend (ObjClass) – The CMS object class from which this one should inherit its attributes. The class given must inherit from Obj. By default, the base class Obj is used.

Returns

ObjClass

Remarks

User-defined page models inherit all methods from Obj.

Example

Create a an abstract class named BaseClass and a subclass named Page:

Copy
const BaseClass = Scrivito.createObjClass({
  attributes: {
    body: 'widgetlist',
    bgColor: ['enum', { values: ['black', 'white', 'grey'] }],
  },
});

class Page extends BaseClass {
  myMethod() {
    return 'cool';
  }
}

Scrivito.provideObjClass('Page', Page);