New in 1.34.0 (BETA)

provideDataClass(name, connection)

Makes external data available to the application.

The data is made available under the specified name and can then be used in textual content by means of placeholders.

Params

  • name (String) – The class name under which the external data will be available.
  • connection (Object) – An object containing asynchronous callbacks for fetching the external data.
    • get (Function) – A callback for fetching a single piece of data by a given ID. See below for details.
    • index (Function) – An optional callback for fetching a set of data. See below for details.
    • create (Function) – An optional callback for creating a single piece of data. See below for details.
    • update (Function) – An optional callback for updating a single piece of data. See below for details.
    • delete (Function) – An optional callback for deleting a single piece of data. See below for details.

Returns

DataClass – A data class that can be used to provide an editing configuration for the external data.

Callbacks

get

The get callback is for fetching a single piece of data by a given ID. Scrivito executes the passed-in function and waits for the returned promise to resolve.

Params

  • id (String) – ID of the data to be fetched. Scrivito supports numeric as well as hexadecimal IDs, but not IDs made up of arbitrary characters.

Returns

Example

index

The index callback is for fetching a set of data. Scrivito executes the passed-in function, providing it with IndexParams, and waits for the returned promise to resolve with an IndexResponse object.

Params

  • params (IndexParams) – an object containing details about which data to fetch.

Returns

  • IndexResponse (Object) – A plain JavaScript object representing the response. This object can have the following properties:
    • results (Array) – An array representing the results. Each result must either be an ID (String) or an Object with an _id (String) property and data properties with String values.
    • continuation (String) – A optional continuation token. It can be used to indicate to Scrivito that not all results have been fetched yet. Scrivito will then use the continuation token to fetch the next results.

Example

create

The create callback is used to create a single piece of data. Scrivito executes the passed-in function, providing it with data, and waits for the returned promise to resolve with a CreateResponse object.

Params

Returns

  • CreateResponse (Object) – A plain JavaScript object representing the external data. This object must have the _id property containing the data ID of the new piece of data. If there are further properties available, the Scrivito SDK will use them to set the local state of the data.

Example

update

The update callback is for updating a single piece of data. Scrivito executes the passed-in function, providing it with data, and waits for the returned promise to resolve with an UpdateResponse object.

Params

Returns

Example

delete

The delete callback is for deleting a piece of data. Scrivito executes the function passed in to the DataClass, providing it with the ID, and waits for the returned promise to resolve.

Params

  • id (String) – ID of the data to be deleted.

Example

Data format

Scrivito expects external data to be passed in as plain JavaScript objects. Data object keys must be valid data identifiers. Values may be either of the String type or null.