Loop through external data
In the previous lesson you created a page that can dynamically display details for a single article. Now you will create a page that displays a list of articles, along with a link to the article detail page.
Goals
- Build a dynamic article list page that can display data from all articles, along with a link to the corresponding article detail page.
- Use the Loop component to handle multiple records.
- Test the dynamic article list page.
Create an articles page#
- Navigate to Experience > Project Map.
- Edit the node Home > Articles.
- Set the following values:
Name Value Node type Composition Composition option Create new Composition type Page - Click Save.
- In the project map, click the node Home > Articles to open the new composition.
Add data resources#
Content Block#
- In the side rail, click .
- Click the button Add data resource.
- Click the add link in the upper right-hand corner of the drawer.
- Select your data source.
Contentful > Contentful
- Enter the following values:
Field Value Archetype Single Entry Allowed Content Types Content Block Name Content Block
Public ID contentBlock
- Click Save.
- Select the entry with the following title:Articles for all your brewing needs
- Click Save.
Articles#
- Select your data source.
Contentful > Contentful
- Enter the following values:
Field Value Archetype Query Allowed Content Types Article Name Articles
Public ID articles
- Click Save.
- Under the field Articles settings, enter the following values:
Field Value Count 25
Sort CreatedAt Sort Order Descending About this step
This entry is only used so the components displayed within Canvas have a value during the authoring process.
- Click Save.
- In the upper right-hand corner of the data resources drawer, click to close the drawer.
Configure the components#
Update Page component#
- Select the Page component.
- Set the following parameters:
Parameter name External field Page Title Articles page
Update Hero component#
- Select the Hero component.
- Set the following parameter values:
Section Parameter name Value Content Eyebrow text Content Title Style H2 Content Description - For the following parameters, clear any existing value and insert the specified dynamic token:
Section Parameter name External field Content Title Content Block Content > fields > title - For the parameter Image, clear the existing value and map to the following custom URL:https://res.cloudinary.com/uniform-demos/image/upload/v1692269405/coffee-marketing/hero-1_vks69p_uywcq7_r0atem.png
Update Breadcrumbs component#
- Select the component Breadcrumbs.
- Set the following parameter values:
Parameter name Value Display Root Node checked Display Placeholder Nodes checked Separator Chevron
Add Grid component#
- Under the Breadcrumbs component, add the component Grid.
- Set the following parameter values:
Parameter name Value Columns Count 3 Gap X Small Gap Y Small - Click to open the structure panel.
- Under the Grid component, find the slot named GRID INNER.
- In this slot, add the component Loop.
- Click to close the structure panel.
About this step
The Loop component is still selected.
- In the right column, click Select.
- In the dropdown, select the data resource Articles Content.
- Select the following node:
Articles Content > items
- Click Connect.
Add Card component#
- Click to open the structure panel.
- Under the Loop component, click .
- Select the component Card.
- Click to close the structure panel.
About this step
The Card component is still selected.
- Set the following parameter values:
Section Parameter name Value Description Line Count Restriction 6 CTA Button Copy Read More
- For the following parameters, clear any existing value and insert the specified dynamic token:
Section Parameter name External field Content Title Articles Content items Loop item > fields > title Content Image Articles Content items Loop item > fields > thumbnail > fields > file > url If you get an error message about the value not being a valid image URL, click in the URL field before the purple text and enter
https:
. After you do this, the image should appear properly.Description Description Articles Content items Loop item > fields > description - In the section CTA, find the parameter Button Link.
- Click Select link.
- Click the tab Project Map.
- Select the node Home > Articles > Article.
- Under the section Article parameters, click .
- Click Insert dynamic token.
Articles Content items Loop item > fields > slug
- Click Connect.
- Click Accept.
Publish & test the composition#
A new composition is not available to visitors until it is published.
- Click Publish... to publish the composition.
- In a new browser tab, open http://localhost:3000/articles
summary
You'll see that by configuring the data resource connections for that single card component, you have a full array of article pages that are dynamically rendered.