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

  1. Build a dynamic article list page that can display data from all articles, along with a link to the corresponding article detail page.
  2. Use the Loop component to handle multiple records.
  3. Test the dynamic article list page.
  1. Navigate to Experience > Project Map.
  2. Edit the node Home > Articles.
  3. Set the following values:
    NameValue
    Node typeComposition
    Composition optionCreate new
    Composition typePage
  4. Click Save.
  5. In the project map, click the node Home > Articles to open the new composition.
  1. In the side rail, click .
  2. Click the button Add data resource.
  3. Click the add link in the upper right-hand corner of the drawer.
  4. Select your data source.

    Contentful > Contentful

  5. Enter the following values:
    FieldValue
    ArchetypeSingle Entry
    Allowed Content TypesContent Block
    NameContent Block
    Public IDcontentBlock
  6. Click Save.
  7. Select the entry with the following title:
    Articles for all your brewing needs
  8. Click Save.
  1. Select your data source.

    Contentful > Contentful

  2. Enter the following values:
    FieldValue
    ArchetypeQuery
    Allowed Content TypesArticle
    NameArticles
    Public IDarticles
  3. Click Save.
  4. Under the field Articles settings, enter the following values:
    FieldValue
    Count25
    SortCreatedAt
    Sort OrderDescending

    About this step

    This entry is only used so the components displayed within Canvas have a value during the authoring process.

  5. Click Save.
  6. In the upper right-hand corner of the data resources drawer, click to close the drawer.
  1. Select the Page component.
  2. Set the following parameters:
    Parameter nameExternal field
    Page TitleArticles page
  1. Select the Hero component.
  2. Set the following parameter values:
    SectionParameter nameValue
    ContentEyebrow text
    ContentTitle StyleH2
    ContentDescription
  3. For the following parameters, clear any existing value and insert the specified dynamic token:
    SectionParameter nameExternal field
    ContentTitleContent Block Content > fields > title
  4. 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
  1. Select the component Breadcrumbs.
  2. Set the following parameter values:
    Parameter nameValue
    Display Root Nodechecked
    Display Placeholder Nodeschecked
    SeparatorChevron
  1. Under the Breadcrumbs component, add the component Grid.
  2. Set the following parameter values:
    Parameter nameValue
    Columns Count3
    Gap XSmall
    Gap YSmall
  3. Click to open the structure panel.
  4. Under the Grid component, find the slot named GRID INNER.
  5. In this slot, add the component Loop.
  6. Click to close the structure panel.

    About this step

    The Loop component is still selected.

  7. In the right column, click Select.
  8. In the dropdown, select the data resource Articles Content.
  9. Select the following node:

    Articles Content > items

  10. Click Connect.
  1. Click to open the structure panel.
  2. Under the Loop component, click .
  3. Select the component Card.
  4. Click to close the structure panel.

    About this step

    The Card component is still selected.

  5. Set the following parameter values:
    SectionParameter nameValue
    DescriptionLine Count Restriction6
    CTAButton CopyRead More
  6. For the following parameters, clear any existing value and insert the specified dynamic token:
    SectionParameter nameExternal field
    ContentTitleArticles Content items Loop item > fields > title
    ContentImageArticles 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.

    DescriptionDescriptionArticles Content items Loop item > fields > description
  7. In the section CTA, find the parameter Button Link.
  8. Click Select link.
  9. Click the tab Project Map.
  10. Select the node Home > Articles > Article.
  11. Under the section Article parameters, click .
  12. Click Insert dynamic token.

    Articles Content items Loop item > fields > slug

  13. Click Connect.
  14. Click Accept.

A new composition is not available to visitors until it is published.

  1. Click Publish... to publish the composition.
  2. 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.