What You are Going to Learn
In this tutorial, you will go through the steps to update the Text Teaser component to use content data sources. You will learn:
- How to update the Text Teaser component to use the data in your content items
- How to map different types of content
- How to make your changes available to authors
Overview
Previously, you learned how to use XM Cloud Components to centrally manage the content of a Text Teaser component and use that component in XM Cloud Pages. You then learned how to create a data model for the Text Teaser component and make it available. Now you will evolve the component itself so it can be used as a reusable visual building block in XM Cloud where the content can be different on each page. To accomplish this, you will map a data source to the visual elements in your component.
For this tutorial, you will:
- Connect the created Text Teaser data source to the Text Teaser Component on the page and map each visual element to fields.
- Share your changes with other authors in XM Cloud
- Configure XM Cloud so that whenever an author drags the Text Teaser component onto the page, they are asked to select an existing piece of content or create a new one.
Prerequisites
In order to complete the following tutorial, you will need these resources:
- A valid organization login for the Sitecore Cloud portal
- An existing XM Cloud environment and site created in Tutorial: How to Set Up and Utilize XM Cloud
- The Text Teaser component created in Tutorial: Create a Component using XM Cloud Component Builder
- The Text Teaser data source created in Tutorial: How to Create a Component Data Template in XM Cloud
- A FEaaS data source configuration done in Tutorial: How to make a data template available to the Component builder in XM Cloud
Map data source fields to XM Cloud Component visual elements
The Text Teaser component that was created in a previous tutorial uses static data in XM Cloud Components. As part of using the new Text Teaser data template, you need to map this Text Teaser data source to the visual elements in XM Cloud Components.
Map component heading element to Headline text field
You are going to start by mapping the headline text field.
-
Switch to the Components tab in the top menu to launch the Components visual builder.
-
Scroll to the section labelled Basic Components. This section will list all the components you have made available in the Basic Components section. Currently, there is only the Text Teaser.
-
Click on the Text Teaser card to launch the editor on this component
-
Click on the primary headline in the Component so that you enter the 'editing' mode for that field.
As you select visual elements in the editor you will see the details on the right change to show you the new options for that visual element. In this case, you can see the Text part in the Content area which is where you need to go next.
-
On the right side panel, click on the Text option. This will show that the text is currently Static
-
Change the mode from Static to Mapped. This will show you the source mapping options.
-
Find and select the Text Teaser source in the list of available sources.
Note that the Sample shows some example fields and their values. This can help you make sure you have the right type of source selected for the component you are editing.
-
Click on the Next button to advance to the Path configuration step. This is where you will map the fields from the template to the visual element.
-
Select the Headline field to map the data from that Text Teaser field to the heading element in the component.
-
Click Complete to finish the mapping process.
Map component sub-heading element to Subheadline text field
You will now repeat the process for the the subtitle/subheading element. You will select the subheading visual element and map that to the Text field "Subheadline" in the Text Teaser template
Challenge: Can you do the mapping with only the information above? If not, continue on for the full detailed steps!
-
Click on the secondary headline/subheadline in the Component so that you enter the 'editing' mode for that field.
The pane on the right updates and you can see the Text part in the Content area which is where you need to go next.
-
On the right side panel, click on the Text option. This will show that the text is currently Static
-
Change the mode from Static to Mapped. This will show you the source mapping options.
-
Click on the Next button to advance to the Path configuration step. This is where you will map the fields from the template to the visual element.
-
Select the Subheadline field to map the data from that Text Teaser field to the heading element in the component.
-
Click Complete to finish the mapping process.
Mapping a Rich Text field to an HTML Block element
In the Text Teaser component that was created in the previous tutorial, the right-side of the component is intended to have a full description (or 'teaser') for the user to read. Initially, the copied content that was used contains several paragraphs and list items, which does not map to a single field. Additionally, the paragraph tags do not render the formatting from a Rich Text field, so even if you have a single paragraph tag this will not meet the need.
In order to create a section of rich content and then map it to a Rich Text field on a data source and preserve the formatting, you need to do some cleanup to the existing content and put in the correct type of element: an HTML Block. In this section of the tutorial, you will clean up the component and map the Rich Text field to an HTML Block.
-
In the Components builder, select the right-side of the Text Teaser component and remove all of the paragraphs of content that are currently there.
-
Above the empty placeholder, click on the Add element button.
-
Select the HTML Block element to insert it into the placeholder.
-
Click on the HTML Block element that was inserted to focus your editing selection.
-
On the right side panel, click on the HTMLContent option. This will show that the text is currently None
-
Map the HTML Block to the Content field on the Text Teaser data source
-
Click Complete to save the mapping changes.
Make the changes to the component available to authors
Now that you have completed all of the mapping changes you will need to make the changes available to Pages by staging the component again.
-
In the Components builder tool, click on the Restage button above the component
Update the existing Text Teaser to use a data source
In the previous tutorial, you added a Text Teaser component to the home page. After making these mapping changes, the existing component will now need a data source to display correctly as there is no more static content on the component. You will now go to Pages and fix the component so that it can pull the data from one of the Text Teaser data sources that were created in this tutorial.
-
Return to the XM Cloud Tools pane. If you've closed that tab, you can get there with these instructions:
- Login to the Sitecore Cloud Portal
- Select your App from the Apps list
- From the flyout panel, select Open app
- At the very top switch to Tools
-
In the Tools page, select the Pages card to launch the Pages editor. The home page will display and you can see that the Text Teaser component is blank.
-
Click on the blank component to select it.
-
In the context menu above the component, click on the Delete action button. This will remove the current version of the component from the page.
-
In the left page, scroll down the Components listing to find the Text Teaser component.
-
Drag the Text Teaser component onto the Pages canvas to add the component to the page. A dialog will display prompting you to assign a content item (data source) to the component.
-
Expand and navigate the displayed Content items tree to find the Text Teasers folder:
Company Dev/Company Dev/Data/Teasers
-
Select the How to Use Components content item.
-
Click the Assign button to connect this content item to the Text Teaser component on the page.
Congratulations! You have now updated the Text Teaser component to work from a piece of re-usable authored content instead of using static content added to the component directly. You also learned how to map visual elements to template fields.