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.

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);