Prismic parameters
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 type | Description |
---|---|
Prismic document | Select a single document from Prismic. |
Prismic Document#
This parameter type allows a Uniform user to select a single Prismic document.
Add parameter to component#
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.
In Uniform, navigate to your component.
Add a new parameter using the parameter type Prismic Document.
The following values can be specified:
Name Description Select Linked Source Specifies which Prismic project is the source for the document that can be selected. Allowed document types Specifies 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. Required Indicates whether the value is required when the component is used. Click Select.
Click the document you want to select.
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.
You will see details about the document you selected, including the title and some metadata.
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-domIn 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 variablecomposition
.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.