close

Filter

loading table of contents...

Studio Developer Manual / Version 2301

Table Of Contents

9.5.7 Client-side initialization of new Documents

With a content initializer you can initialize the properties of a newly created document. A content initializer will be called while a new content object is being created by the NewContentAction. Only one initializer can be defined for each document type. You must register custom initializers with the global @coremedia/studio-client.main.editor-components/sdk/editorContext. Simply call the registerContentInitializer(contentTypeName, initializer) method.

The following code defines a simple initializer that sets the content's language property to German by default:

import StudioPlugin from "@coremedia/studio-client.main.editor-components/configuration/StudioPlugin";
import IEditorContext from "@coremedia/studio-client.main.editor-components/sdk/IEditorContext";
import ContentInitializer from "@coremedia-blueprint/studio-client.main.blueprint-forms/util/ContentInitializer";
import Content from "@coremedia/studio-client.cap-rest-client/content/Content";

class MyStudioPlugin extends StudioPlugin{

  //...

  init(editorContext: IEditorContext): void {
    editorContext.registerContentInitializer("CMTeaser", MyStudioPlugin.initLanguage);
  }

  static initLanguage(content:Content):void {
    ContentInitializer.setProperty(content, "locale", "de");
  }
}

Example 9.28. Defining a content initializer


Client-side initialization might be sufficient for simple initialization scenarios. If you have complex requirements, consider using server-side initialization: Refer to Section 9.21.2, “Intercepting Write Requests” for details.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.