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.

Example

See Letting Editors Create Web Interfaces Utilizing Data for a detailed example.

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

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

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

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

Example

Data property names

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

Data IDs

The ID of a piece of data must be a string and can be one of:

  • A hexadecimal ID with eight or more characters (e.g. fedcba9876543210)
  • A numeric ID consisting of decimal characters (e.g. 1234)
  • A composite ID with groups of hexadecimal or numeric IDs separated by dashes (e.g. a1b2c3d4-1-dea8be6f

Scrivito does not support data IDs made up of arbitrary characters.