Last updated November 17, 2023.
When you have data that resides in Contentful that you want to use in your Builder app, you can use Builder's data provider plugins to fetch and display it on your site. When you have data such as content types and content entries that reside in Contentful that you want to use in your Builder app, you can use Builder's data provider plugins to fetch and display it on your site. This allows you to connect that content to any component within the Visual Editor without the need to wait on any migration.
Goals
This tutorial shows you how to get data from Contentful's composable content platform into your Builder app through the following:
- Enabling Contentful
- Authenticating to Contentful
- Using your data in your Builder app
What we'll create
In this example, we'll pull in data from Contentful's content management system about historical figures. Our layout uses one of the Builder.io built-in templates to display some leaders from the past. You can duplicate what we have or create your own data.
Image credits:
If you'd like these images, you can find them on Wikipedia.
- Photo of Queen Liliʻuokalani is by James J. Williams.
- Photo Emperor Shōwa (Hirohito) is from the Imperial Household Agency.
- Portrait of Shaka kaSenzangakhona is by James King, 1824.
- Portrait of Queen Elizabeth I is by an unknown artist, and is known as the "Darnley Portrait".
The sample data
In Contentful, we have a Content Model called Monarch.
Within Monarch, we have a number of fields, Name, Place, Reign, Image, and Image Credit.
Enabling Contentful
To enable a third-party data provider, you have to configure Builder to be able to work with the provider.
Open a Page in the Builder Visual Editor.
In the Page, open the Data tab.
The Data tab displays the sources available. Builder as a data source works by default, but the other options need you to enable them. In this example, we’ll enable Contentful, so click the icon for Contentful.
Builder prompts you to enable the plugin. Click Enable Contentful Plugin.
Authenticating to Contentful
In order for Builder and Contentful — or other data provider — to communicate, you must authenticate from within Builder.
When you enable a data provider, Builder prompts you to configure your settings at the bottom of the screen.
Click Configure so you can authenticate.
Tip: If you miss this prompt, you can still continue setting up your data provider by going to Integrations and clicking on the Settings button for that data provider.
In the settings dialogue, enter your Space ID and Access token (called Content Delivery API - access token in Contentful), both of which you can find in your Contentful account under Settings -> API Keys.
Click the Connect button.
Using your Contentful data
Now that you've authenticated, click on the Contentful icon or +Connect Data in the Data tab to get to your resources.
Select Monarch.
Now that we are connected to our data, we need something on the page to display it. We'll use a pre-made template included in Builder. Under the Insert tab, in the Featured section, hover over Columns and drag in Gifts x 4 onto the page.
On the Data tab, your Contentful Monarch should be featured at the top. Click Pick an Entry.
Select Queen Liliʻuokalani.
Select the first heading.
On the Options tab, click the Data Binding icon with the four dots in the upper right corner.
Scroll down or type to filter and select Monarch - Fields - Name.
Now "Queen Liliʻuokalani" populates the text field.
There's also a note that the text field is bound to dynamic data.
Tip: If you need to change the data you're binding to, click the same Data Binding icon to the right of the note in the Options tab.
Repeat this process for the other fields, such as place and reign.
Adding an image
Select the placeholder image in the template. With the image selected, you can bind the monarchʻs picture.
To find the Queen's photo, click the Bind Data icon to the right of the Image Options tab.
Select Monarch - Fields - Image - Fields - File - Url.
The Queen's image should show up when you select it.
Adding a second data source
Now that you've added one Monarch, you can add many more. To get to our other historical figures, we need to add more Monarchs so we can get to their data.
The Data tab now has the current Monarch, but we need to add another. Click the +Connect Data button and select Contentful or just click the Contentful icon.
When prompted, choose Monarch.
Now Monarch 2 appears in the Data tab.
To make the second Monarch's data available, you need to select it so Builder knows which Monarch to use for Monarch 2. Click on the three dots to the right of Monarch 2 to expand the options. Click the Pick an Entry button.
Select another Monarch to associate it with Monarch 2.
Now, when you click the Bind Data icon for the different elements, the Monarch 2 data is available.
What's next
This article guided you through pulling in data from Contentful's headless CMS. Data binding is a robust feature available throughout Builder, indicated by the icon with four dots. You can use data binding to get styles, list data, and you can even filter your results.
Once you have your data from Contentful you can utilize Builder for visual editing. Dive into our docs for additional use cases and learn how to integrate Builder with other technologies in any tech stack. Streamline your digital experiences for developers and non-technical users.