Last Updated on January 8, 2025 by sandeeppote

This is a very common scenario where a background image needs to be set to certain components. Banner’s on any page on your website is a very common place to have a background image.

This blog assumes you have setup the Foundation Head setup or have your own Nextjs project setup implemented using the Sitecore NextJS SDK.

Note: This is not specific to XM Cloud but for any Headless implementation

Foundation Head already has an example on setting the background image using params. In this blog post will explore how this works and where in Sitecore the image can be applied. Will see how this can applied using using OOTB _Background Image item.

To apply image background using rendering parameters to the container see this blog here

Applying background image using rendering field to the components

Background image can be applied to components inheriting the existing __Background Image item to the custom component template.

Create a template for your component. Here I am creating a Banner component-

Inherit _Background Image from /sitecore/templates/Foundation/Experience Accelerator/Presentation/_Background Image

_Background Image has “Background Image” and “Stretch mode” field.

Note that there is a space between the field names, although not recommended but this comes OOTB.

Create a “Banner” JSON Rendering and provide the “Parameters Template”, “Datasource Location” and “Datasource Template” as per your requirement and add this rendering to the “Available Renderings”

Create a Nextjs component in sxastarter project

Note below how the “Background Image” field is set. This is due to the same in field name. Not recommended but this is OOTB.

View this gist on GitHub

Experience Editor-

Add a container component in Main placeholder-

Add a newly created component (Banner) in Container placeholder-

Create or select associated content

Once the component is added you should see the button to Add Background Image ( ths is added when the template inherits from _Background Image template.

Select the Background Image and Save-

You should now able to see the background image to component-

Rendering Host-

Reference-

https://doc.sitecore.com/xmc/en/users/xm-cloud/add-a-background-image.html