Contentstack parameters

After you add the Contentstack integration to your Uniform project, a number of new parameter types will be available when you configure components using Uniform Canvas.

Parameter typeDescription
Contentstack Entry SelectorSelect a single entry from Contentstack.
Contentstack Multi Entry SelectorSelect multiple entries from Contentstack.
Contentstack Query Entry SelectorSpecify search criteria that's used to select a single or multiple entries from Contentstack.

Contentstack Entry Selector#

This parameter type allows a Uniform user to select a single Contentstack entry.

To allow a user to select an entry from Contentstack, you must add a parameter to a component. The parameter is used to store the identifier to the selected entry when the user selects an entry.

  1. In Uniform, navigate to your component.

  2. Add a new parameter using the parameter type Contentstack Entry Selector.

  3. The following values can be specified:

    NameDescription
    Allowed Content TypesSpecifies which content types will be available to select from when the parameter value is edited. You can select multiple content types to allow the user to select from a larger set of entries.
    RequiredIndicates whether the value is required when the component is used.
    parameter-config
    Contentstack Entry Selector parameter with a single content type selected.

When you use a component with a Contentstack Entry Selector parameter, by default no entry will be selected. You are prompted to select an entry.

  1. Click Select.

    edit-value-default
  2. Click the entry you want to select.

    edit-value-filters

    About this step

    A couple of filters are available. The dropdown allows you to filter by content type. The text box allows you to filter by entry title.

  3. Click Accept to save your selection.

    edit-value-selected
  4. You will see details about the entry you selected, including the title and some metadata.

    edit-value-saved

    About this step

    After your selection is saved, you are presented with the following options:

    • If you want to edit the selected entry in Contentstack, click Edit.
    • If you want to deselect the entry, click Unlink.

When an entry is selected, Uniform only stores the identifier for the entry. Your front-end application must retrieve the details for the entry. Uniform provides an enhancer to simplify this process.

tip

Using the enhancer provided by Uniform saves you from having to write logic to interact directly with Contentstack.

How Uniform stores the selected entry#

The following is an example of what Uniform stores for the parameter.

{ "type": "contentstackEntrySelector", "value": { "entryUid": "###################", "contentTypeUid": "###################" } }

There are two identifiers in this value:

  1. The entry that was selected.
  2. The content type for the selected entry.

Uniform provides an enhancer so you don't need to write the API calls to Contentstack to retrieve data for entries.

  1. In Contentstack, create an API key and delivery token for the enhancer to use to make API calls to Contentstack.

  2. Add the following npm packages to your front-end application:

    npm install contentstack
    npm install @uniformdev/canvas
    npm install @uniformdev/canvas-contentstack
  3. In a text editor, open the file where you retrieve the composition definition from Uniform.

    About this step

    You are looking for the code calls the async function getComposition. The code below assumes the object returned is set in a variable composition.

  4. Add the following import statements (highlighted lines represent Contentstack specific additions):

    import { EnhancerBuilder, enhance } from '@uniformdev/canvas'; import contentstack from 'contentstack'; import { createContentstackEnhancer, CANVAS_CONTENTSTACK_PARAMETER_TYPES, } from '@uniformdev/canvas-contentstack';
  5. Create an instance of Contentstack enhancer (depending on your region):

    const csClient = contentstack.Stack({ api_key: '!!! YOUR CONTENTSTACK API KEY !!!', delivery_token: '!!! YOUR CONTENTSTACK DELIVERY TOKEN !!!', environment: '!!! YOUR CONTENTSTACK ENVIRONMENT !!!', region: contentstack.Region.US, });

    About this step

    Please use environment variables here (process.env.CONTENTSTACK_KEY for example) instead of hard-coded values.

  6. Create an instance of enhancer for Entry parameters:

    const entryEnhancer = createContentstackEnhancer({ client: csClient });
  7. Register the enhancer for this parameter type with EnhancerBuilder. This registers the enhancer to be used for any occurrence of the Contentstack Entry Selector parameter.

    await enhance({ composition, enhancers: new EnhancerBuilder() .parameterType( CANVAS_CONTENTSTACK_PARAMETER_TYPES, entryEnhancer ), context: {}, });

Next steps

Now the parameter value in the composition is mutated to include the field values for the selected Contentstack entry (instead of just being identifiers).

Contentstack Multi Entry Selector#

This parameter type is added and edited the same way as Contentstack Entry Selector. When editing the parameter value, you can select additional entries by clicking the button Select new.

multi-entry-selector
Example of the editing interface for an Contentstack Multi Entry Selector parameter on a component.

When entries are selected, Uniform only stores the identifiers for the entries. Your front-end application must retrieve the details for the entries. Uniform provides an enhancer to simplify this process.

tip

Using the enhancer provided by Uniform saves you from having to write logic to interact directly with Contentstack.

The following is an example of what Uniform stores for the parameter.

{ "type": "contentstackMultiEntrySelector", "value": { "entries": [ { "entryUid": "###################", "contentTypeUid": "places" }, { "entryUid": "###################",, "contentTypeUid": "places" } ] } }

Uniform provides an enhancer so you don't need to write the API calls to Contentstack to retrieve data for entries.

  1. In Contentstack, create an API key and delivery token for the enhancer to use to make API calls to Contentstack.

  2. If you haven't already, add the following npm packages to your front-end application:

    npm install contentstack
    npm install @uniformdev/canvas
    npm install @uniformdev/canvas-contentstack
  3. In a text editor, open the file where you retrieve the composition definition from Uniform.

    About this step

    You are looking for the code calls the async function getComposition. The code below assumes the object returned is set in a variable composition.

  4. Add the following import statements, notice we import a different enhancer function createContentstackMultiEnhancer this time:

    import contentstack from 'contentstack'; import { EnhancerBuilder, enhance } from '@uniformdev/canvas'; import { createContentstackMultiEnhancer, CANVAS_CONTENTSTACK_MULTI_PARAMETER_TYPES } from '@uniformdev/canvas-contentstack';
  5. Create an instance of Contentstack client (depending on your region):

    const csClient = contentstack.Stack({ api_key: '!!! YOUR CONTENTSTACK API KEY !!!', delivery_token: '!!! YOUR CONTENTSTACK DELIVERY TOKEN !!!', environment: '!!! YOUR CONTENTSTACK ENVIRONMENT !!!', region: contentstack.Region.US, });

    About this step

    Please use environment variables here (process.env.CONTENTSTACK_KEY for example) instead of hard-coded values.

  6. Create an instance of the multi enhancer by passing the client into it:

    const multiEntryEnhancer = createContentstackMultiEnhancer({ client: csClient });
  7. Add contentstackMultiEnhancer to EnhancerBuilder. This step registers the enhancer to be used for any occurrence of the Contentstack Multi Entry Selector parameter:

    await enhance({ composition, enhancers: new EnhancerBuilder() .parameterType( CANVAS_CONTENTSTACK_MULTI_PARAMETER_TYPES, multiEntryEnhancer ), context: {}, });

Next steps

Now the parameter value in the composition is mutated to include the field values for the selected Contentstack entries (instead of just being identifiers).

Contentstack Query Entry Selector#

This parameter type allows a Uniform user to configure a query that will determine the Contentstack entries that are retrieved.

This parameter type is added the same way as Contentstack Entry Selector.

Configuring this parameter type involves specifying the way a product search should work. You are able to control the following search settings:

FieldDescription
Filter by entry typeOnly entries that match the selected entry type are included.
CountThe maximum number of entries that are returned.
SortThe entry field used to sort the entries that are returned.
Sort OrderWhether the entries should be sorted in ascending or descending order.
edit-parameter-value
Example of the editing interface for a Contentstack Query Entry Selector parameter on a component.

When an entry query is configured, Uniform only stores the search criteria, not the results of the search. Your front-end application must perform the search using that criteria. Uniform provides an enhancer to simplify this process.

tip

Using the enhancer provided by Uniform saves you from having to write logic to interact directly with Contentstack.

The following is an example of what Uniform stores for the parameter.

{ "type": "contentstackQueryEntrySelector", "value": { "contentType": { "id": "places", "name": "Places" }, "limit": 2, "sortOrder": "asc" } }

There are three identifiers in this value:

  1. The content type to use in the search.
  2. The maximum number of entries to search for.
  3. The sort order applies to the search results.

Uniform provides an enhancer so you don't need to write the API calls to Contentstack to retrieve data for entries.

  1. In Contentstack, create an API key and delivery token for the enhancer to use to make API calls to Contentstack.

  2. If you haven't already, add the following npm packages to your front-end application:

    npm install contentstack
    npm install @uniformdev/canvas
    npm install @uniformdev/canvas-contentstack
  3. In a text editor, open the file where you retrieve the composition definition from Uniform.

    About this step

    You are looking for the code calls the async function getComposition. The code below assumes the object returned is set in a variable composition.

  4. Add the following import statements:

    import contentstack from 'contentstack'; import { EnhancerBuilder, enhance } from '@uniformdev/canvas'; import { createContentstackQueryEnhancer, CANVAS_CONTENTSTACK_QUERY_PARAMETER_TYPES, } from '@uniformdev/canvas-contentstack';
  5. Create an instance of Contentstack client (depending on your region):

    const csClient = contentstack.Stack({ api_key: '!!! YOUR CONTENTSTACK API KEY !!!', delivery_token: '!!! YOUR CONTENTSTACK DELIVERY TOKEN !!!', environment: '!!! YOUR CONTENTSTACK ENVIRONMENT !!!', region: contentstack.Region.US, });

    About this step

    Please use environment variables here (process.env.CONTENTSTACK_KEY for example) instead of hard-coded values.

  6. Create an instance of enhancer for Query parameters:

    const queryEnhancer = createContentstackQueryEnhancer({ client: csClient });
  7. Register this enhancer with EnhancerBuilder:

    await enhance({ composition, enhancers: new EnhancerBuilder() .parameterType( CANVAS_CONTENTSTACK_QUERY_PARAMETER_TYPES, queryEnhancer ), context: {}, });

    About this step

    This registers the enhancer to be used for any occurrence of the Contentstack Query Entry Selector parameter.

Next steps

Now the parameter value in the composition is mutated to include the field values for the selected Contentstack entries (instead of just being settings).