Image Placeholder

Show React Component Properties on the Page Editor – XM Cloud

If you are building a custom component in React but would like to provide content authors the ability to edit the properties of the component on the Page Editor in XM Cloud, then this blog post could be helpful.

Example: To build a component by providing Sitecore managed data to a third party API like Google Maps API.

Sitecore Managed Data:

  • Map Settings
  • Locations

Steps:

We will set/get the Map settings by using the rendering parameters.

  1. Create a rendering in Sitecore, for example: Locations Finder. Make sure the component name is the one that’s registered in your react solution(index.ts).

custom

  1. Let’s set other properties on this rendering like Parameter’s Template, Datasource Location, Datasource Template etc. Then you need to create a rendering parameters template for the rendering that registers the react component.
  • Inherit the Rendering Params and Base Parameters.

custom

  • Add new properties.

custom

  • Open the rendering and set the Parameters template as shown below:

custom

  1. Now we will set/get the Locations data.
  • Create a location template that has the properties you would like to map to an address on Google Map API.

custom

  • Create a Datasource folder having locations based on the template in the above step.

custom

  • Specify this data source location on your rendering, for example:

custom

  • Now, write a GraphQL query to retrieve this data as shown below:

Playground:

custom

React Code:

  1. Define the query:

custom

  1. Define the function to execute the query:

custom

  1. Execute the query to get props with all the Sitecore managed data (Locations and Map Settings):

custom

  1. Map the retrieved data to the Google Map API.

Output on Pages in XM Cloud:

custom

Output on Rendering Host:

custom

References: