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.
    • index (Function) – An optional callback for fetching a set of data.
    • create (Function) – An optional callback for creating a single piece of data.
    • update (Function) – An optional callback for updating a single piece of data.
    • delete (Function) – An optional callback for deleting a single piece of data.

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 or an Object with an _id property containing the ID, and data properties with String values. For the ID format, see Data IDs.
  • continuation (String) – An 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.
  • [New in 1.40.0]count (Number) – The optional total number of items matching params.filters() and params.search(), but ignoring params.limit(). If params.includeCount() is true, count must be present in the response for DataScope#count to return meaningful data.

Example

create

The create callback is for creating 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

Returns

  • UpdateResponse (Object) – An optional plain JavaScript object representing the external data. If the object is present, the Scrivito SDK will use its properties to update the local state of the data.

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 can be one of:

  • String: A hexadecimal ID with eight or more characters (e.g. fedcba9876543210), or a composite ID with groups of hexadecimal or numeric IDs, optionally separated by dashes (e.g. a1b2c3d4-1-dea8be6f) 
  • [New in 1.39.0]Number: A numeric ID consisting of an integer value ≥0 (e.g. 1234). IDs of this data type must be a safe integer.

IDs made up of any characters can be handled by converting them to hexadecimal character strings.