How to Create a Custom Component in XM Cloud.

The best practice for creating a component module is to navigate to Settings -> Project -> [Site Name]. 

This allows us to use the component across different sites as well. 

To create the module, right-click on the project, select "Insert," and then click on "Headless Module." A popup modal will appear.

 


Specify the module name as the component name. Choose the desired path for grouping the components. The best way to organize them is to select your site name folder under the project.


Create a rendering.

Instead of creating a rendering, it’s best to clone a rendering and then update it accordingly. For example, clone a Promo rendering and rename it to Text Card.

/sitecore/layout/Renderings/Feature/JSS Experience Accelerator/Page Content/Promo

To clone the rendering, right-click on the promo, select "Scripts," and then choose "Clone Rendering."

 


Update the rendering name and select the path to your component folder that was created during the module/component creation.


In the Parameters and Data source tabs, select the second option to copy the original rendering parameters, ensuring our new component remains separate. 



Remove the empty spaces between component names for easier access in Next.js.



Let’s remove the sub-items from the text card component, as we have different field sets.



A new field has been created for the Text Card Component.


Next, let's import the component (module) into my site using the script.

Right-click on the site, then go to Scripts and select "Add Site Module."

 


A popup modal will appear, allowing you to select the new module that we created.

Now the appropriate template item folder should be created under the Data Folder, and I have created the data item inside the item folder.


Notice that the rendering is created under Presentation -> Available Renderings. This section is used to display the component in the experience editor.


Let's go to the XM Cloud page editor and drag your component to the appropriate page.

If it’s not displayed, ensure all items related to the module are published in the component section on XMC.

It now shows a message indicating that the JSS component is missing.



Are you curious about why the JSS error was displayed? Please visit the blog below for guidance on creating a component in a Next.js app and its integration with XM Cloud.

Comments

Popular posts from this blog

How to Enable Voice Search in Sitecore Content Editor

How to Create a Component in Next.js for XM Cloud