Test Enterprise-Class Web CMS Scrivito Free for 30 Days
Test Scrivito Free for 30 Days

provideWidgetClass(name, widgetClassOrDefinition)

Creates a widget class or registers an already existing class.

If a class is given, this function registers an unnamed CMS widget class under the given name. Otherwise, Scrivito.provideWidgetClass generates a widget class using the given definition.

Widget classes serve as boilerplates for CMS widgets. Their main purpose is to define the attributes the instances require, for example an html attribute named “content” and a string attribute named “summary”.

Scrivito.provideWidgetClass('NewsTextWidget', { attributes: { content: 'html', summary: 'string', }, // onlyInside: 'ArticlePage', });


  • name (String) – The name of the CMS widget class.
  • contentClassOrOptions (Class, Object) – Options for generating a widget class (see below) or an already generated class that Scrivito should register.


  • attributes (Object) – The attribute definition of the CMS widget 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.
  • extractTextAttributes (Array of String) – The names and order of the attributes to be used by Scrivito.extractText. Default: []. The following attribute types are supported:
    • string
    • html
    • widgetlist
  • extend (WidgetClass) - The CMS widget class from which this one should inherit its attributes. The specified class must inherit from Widget. By default, the base class Widget is used.

  • onlyInside (String or Array of String) – Optionally, a single page or widget class name (string) or several such names (array) specifying the class(es) in whose instances widgets of this class must be contained. So, instances of this widget class cannot be placed on pages or into widgets of any other classes than the ones specified here.


Create an advanced image widget class with support for some fancy features:

Scrivito.provideWidgetClass('AdvancedImageWidget', { attributes: { image: 'reference', caption: 'string', zoomTo: ['enum', { values: ['none', 'left', 'center', 'right'] } ], }, });

Create a TextWidget widget whose text attribute is used by Scrivito.extractText:

Scrivito.provideWidgetClass('TextWidget', { attributes: { text: 'html', alignment: ['enum', { values: ['left', 'center', 'right'] }], }, extractTextAttributes: ['text'], });

Create a FactWidget widget whose key and value attributes are used by Scrivito.extractText:

Scrivito.provideWidgetClass('FactWidget', { attributes: { key: 'string', value: 'string', }, extractTextAttributes: ['key', 'value'], });

Create an abstract BaseClass and a subclass of it named AdvancedImageWidget:

const BaseClass = Scrivito.createWidgetClass({ attributes: { image: 'reference', }, }); class AdvancedImageWidget extends BaseClass { myMethod() { return 'cool'; } } Scrivito.provideWidgetClass('AdvancedImageWidget', AdvancedImageWidget);