Prismic parameters

After you install the Prismic integration, the following parameter types are available. You can use these to incorporate content from Prismic into your components and compositions.

Parameter typeDescription
Prismic documentSelect a single document from Prismic.

This parameter type allows a Uniform user to select a single Prismic document.

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

  1. In Uniform, navigate to your component.

  2. Add a new parameter using the parameter type Prismic Document.

  3. The following values can be specified:

    NameDescription
    Select Linked SourceSpecifies which Prismic project is the source for the document that can be selected.
    Allowed document typesSpecifies which document types will be available to select from when the parameter value is edited. You can select multiple document types to allow the user to select from a larger set of documents.
    RequiredIndicates whether the value is required when the component is used.

    Click Select.

    edit-value-default

    Click the document you want to select.

    edit-value-filters

    About this step

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

    Click Accept to save your selection.

    edit-value-selected

    You will see details about the document 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 document in Prismic, click Edit.
    • If you want to deselect the document, click Unlink.
    The document that was selected.The source key for the linked content source.

    In Prismic, get the following values:

    • Access token (required if your API is secured)
    • Repository ID

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

    @prismicio/client @uniformdev/canvas-prismic prismic-dom

    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.

    Add the following import statements:

    import { EnhancerBuilder, enhance } from '@uniformdev/canvas'; import { createPrismicEnhancer, PrismicClientList, CANVAS_PRISMIC_PARAMETER_TYPES, } from '@uniformdev/canvas-prismic'; import * as Prismic from '@prismicio/client'; import PrismicDOM from 'prismic-dom';

    Add the following code:

    const endpoint = Prismic.getEndpoint('!!! YOUR PRISMIC REPOSITORY ID !!!'); const client = Prismic.createClient(endpoint, { accessToken: '!!! YOUR PRISMIC ACCESS TOKEN (OPTIONAL) !!!', });

    About this step

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

    Add the following code:

    const clientList = new PrismicClientList({ client }); const prismicEnhancer = createPrismicEnhancer({ clients: clientList });

    Add the following code:

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

    About this step

    This registers the enhancer to be used for any occurrence of the Prismic Document parameter.