Skip to main content

Use parameter

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 is 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.

Add parameter to component

In order 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 in order 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.

Edit parameter value

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 selected 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 unselect the entry, click Unlink.

Configure an enhancer

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.

Add the enhancer

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

tip

For more information about the enhancer, see the package documentation.

  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:

    contentstack
    @uniformdev/canvas
    @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 { EnhancerBuilder, enhance } from '@uniformdev/canvas';
    import {
    createContentstackEnhancer,
    CANVAS_CONTENTSTACK_PARAMETER_TYPES,
    } from '@uniformdev/canvas-contentstack';
    import contentstack from 'contentstack';
  5. Add the following code (depending on your region):

    const client = 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

    We recommend you moving the Contentstack credentials to environment variables rather than hard-coding them in the front-end app.

  6. Add the following code:

    const contentstackEnhancer = createContentstackEnhancer({ client });
  7. Add the following code:

    await enhance({
    composition,
    enhancers: new EnhancerBuilder().parameterType(
    CANVAS_CONTENTSTACK_PARAMETER_TYPES,
    contentstackEnhancer
    ),
    context: {},
    });
    About this step

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

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.

Configure an enhancer

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.

How Uniform stores the selected entries

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

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

Add the enhancer

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

tip

For more information about the enhancer, see the package documentation.

  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:

    contentstack
    @uniformdev/canvas
    @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 { EnhancerBuilder, enhance } from '@uniformdev/canvas';
    import {
    createContentstackEnhancer,
    CANVAS_CONTENTSTACK_MULTI_PARAMETER_TYPES,
    } from '@uniformdev/canvas-contentstack';
    import contentstack from 'contentstack';
  5. Add the following code (depending on your region):

    const client = 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

    We recommend you moving the Contentstack credentials to environment variables rather than hard-coding them in the front-end app.

  6. Add the following code:

    const contentstackEnhancer = createContentstackEnhancer({ client });
  7. Add the following code:

    await enhance({
    composition,
    enhancers: new EnhancerBuilder().parameterType(
    CANVAS_CONTENTSTACK_MULTI_PARAMETER_TYPES,
    contentstackEnhancer
    ),
    context: {},
    });
    About this step

    This registers the enhancer to be used for any occurrence of the Contentstack Multi 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 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.

Add parameter to component

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

Edit parameter value

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.

Configure an enhancer

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.

How Uniform stores the selected settings

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.

Add the enhancer

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

tip

For more information about the enhancer, see the package documentation.

  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:

    contentstack
    @uniformdev/canvas
    @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 { EnhancerBuilder, enhance } from '@uniformdev/canvas';
    import {
    createContentstackEnhancer,
    CANVAS_CONTENTSTACK_QUERY_PARAMETER_TYPES,
    } from '@uniformdev/canvas-contentstack';
    import contentstack from 'contentstack';
  5. Add the following code (depending on your region):

    const client = 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

    We recommend you moving the Contentstack credentials to environment variables rather than hard-coding them in the front-end app.

  6. Add the following code:

    const contentstackEnhancer = createContentstackEnhancer({ client });
  7. Add the following code:

    await enhance({
    composition,
    enhancers: new EnhancerBuilder().parameterType(
    CANVAS_CONTENTSTACK_QUERY_PARAMETER_TYPES,
    contentstackEnhancer
    ),
    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).