Synchronizing items between environments with Sitecore Serialization. The repository already contains the necessary setup for enabling serialization if you are using an official Sitecore XM Cloud foundation template.
Pre-requisite- Setup Sitecore local instance for XM Cloud development. See this blog << Blog to setup Sitecoer instance>>
You may already see the rendering host module setup in the forked repository.

This should be available in the src folder.
Lets sync the sxastarter site created earlier whilst setting up the SXA Headless Site. << Blog post to setuop SXA headless site>>.
Please note this might not be the method you want to sync the items. Ideally you should create project in XM Cloud and site created in XM Cloud environment. I am doing the other way just to demo.
Create various modules to sync your locally created site to serialize the items
This should help to push the config and items to repository and deploy to XM Cloud later.
Sync templates-
Create a scxmcloud.templates.module.json in src folder.
We are trying to serialise templates to local. These items will be searlised-

{
"$schema": "../.sitecore/schemas/ModuleFile.schema.json",
"namespace": "SCXMCloud.Templates",
"items": {
"includes": [
{
"name": "scxmcloud.project.templates",
"path": "/sitecore/templates/Project",
"allowedPushOperations": "CreateUpdateAndDelete"
}
]
}
}
scope by default is ItemAndDescendants. Hence not defined. Any new templates added here will be auto serialised. allowedPushOperations is set to CreateUpdateAndDelete. Like wise define the same for Feature and Foundation folders.

Define the same for Content (if required) or specific items, Media Library and Layout but this may be site specific.
For media I have configured following – Where scope id Single item and allowedPushOperations is CreateOnly, so these items are created only once.
{
"$schema": "../.sitecore/schemas/ModuleFile.schema.json",
"namespace": "SXAStarter.Media",
"items": {
"includes": [
{
"name": "scxmcloud.project.media",
"path": "/sitecore/media library/Project/scxmcloud",
"allowedPushOperations": "CreateOnly",
"scope": "SingleItem"
},
{
"name": "sxastarter.project.media",
"path": "/sitecore/media library/Project/scxmcloud/sxastarter",
"allowedPushOperations": "CreateOnly"
}
]
}
}
For Palcholder settings and Renderings- Configure same for Feature and Foundation folder.
{
"$schema": "../.sitecore/schemas/ModuleFile.schema.json",
"namespace": "SXAStarter.Layout",
"items": {
"includes": [
{
"name": "sxastarter.project.placeholder",
"path": "/sitecore/layout/Placeholder Settings/Project/scxmcloud",
"allowedPushOperations": "CreateUpdateAndDelete"
},
{
"name": "sxastarter.project.renderings",
"path": "/sitecore/layout/Renderings/Project/scxmcloud",
"allowedPushOperations": "CreateUpdateAndDelete"
}
]
}
}
For content- I am searlising the the Site Collection and setting this as CreateOnly with scope defaulting to ItemAndDescendants
{
"$schema": "../.sitecore/schemas/ModuleFile.schema.json",
"namespace": "SXAStarter.Content",
"items": {
"includes": [
{
"name": "sxastarter.content",
"path": "/sitecore/content/scxmcloud",
"allowedPushOperations": "CreateOnly"
}
]
}
}
Finally you should have following modules depending upon the youe site requirements and configuration.
Connect the local environment
After SCS configuration you should connect to local environment. To do so use the following command
This will add the endpoint in user.json file located in .sitecore folder. Alrthough there is a default endpoint which should suffice. Provide your Sitecore instnace host name as appropriate.
dotnet sitecore connect --ref xmcloud --cm https://xmcloudcm.localhost --allow-write true -n local

Local environment should be connected and now can perform sync operations.
An entry will be added in user.json file.

Next pull the items from local Sitecore instance-
dotnet sitecore ser pull -n "local"
If you see this error – ensure the names should be unique. I did a mistake by providing same name in templates module

If you see this error ensure the items to be searialised should be repeated in any other module or any other name. You may also exclude the paths for Feature and Foundation folders – /sitecore/layout/Renderings/Feature/Experience Accelerator
/sitecore/layout/Renderings/Feature/Experience Accelerator

Finally we should have the items seraliased to the items folder-


Items are serliased to support the Home page-
Please note I have synchornised Site Collection, Site and all items of the site.

Managed to have built the home page with some images and texts.

Push these changes to the repo we forked.
Reference-
Next will configure Project, environment and deploy the Site to XM Cloud.