Tags

, , , , , , ,

Hi Friends,

This Article extends my previous Article on “Setup Serialization in XM Cloud using CLI“.

Once we have covered the first step, We will check how to use the Serialization for Multi-site?

Serialization in multi-site setups demands meticulous configuration. Each site’s settings, templates, and content structures need to be captured accurately to ensure smooth deployment across environments.

To get the serialization for multi-site, you need to setup the folder structure of the code and *.module.Json files and run the commands.

For our Multi site XM Cloud applications, We made the structure as below. The main user.json file is located in the root of the project. We placed other sites specific module.json in the “Travel Sites” folder directly next to the code of each site. We can separate out the content serialization based on the Site. There are parameters we can provide to just get new content from different environments.

  • MyXMCProject
    • .sitecore/user.json
    • src
      • Apps
      • Main Site
        • All Code for Main Site
      • *.module.json
      • items –> Folder contains the items for Main Site
      • My Site
        • Site A
        • Site B
        • items
        • Separate *.module.json files for each Site

We have setup a primary site which is at the Root. Below setup shows the another group of sites located under MySites folder. We have SiteA.module.json and SiteB.module.json located under the MySites.

To illustrate the configuration, let’s delve into example JSON files representing the serialization setup for two hypothetical sites: Site A and Site B. These files encapsulate the necessary configurations for serialization, including templates, layouts, renderings, and content items unique to each site.

  • siteA.json: Contains serialization configurations specific to Site A.
  • siteB.json: Contains serialization configurations specific to Site B.

Once the JSON files are defined, executing PowerShell commands via Sitecore CLI facilitates serialization. Below are the essential commands to execute:

SiteA.module.json – Serialization Configuration file for the SiteA

{
  "namespace": "Site-A",
  "items": {
    "includes": [
      {
        "name": "A-renderings",
        "path": "/sitecore/layout/Renderings/Project/My Sites/Site-A",
        "allowedPushOperations": "createAndUpdate"
      },
      {
        "name": "A-placeholders",
        "path": "/sitecore/layout/Placeholder Settings/Project/My Sites/Site-A",
        "allowedPushOperations": "createAndUpdate"
      },
      {
        "name": "A-templates",
        "path": "/sitecore/templates/Project/My Sites/Site-A",
        "allowedPushOperations": "createAndUpdate"
      }
    ]
  }
}

SiteB.module.json – Serialization Configuration file for the SiteB

{
  "namespace": "Site-B",
  "items": {
    "includes": [
      {
        "name": "B-renderings",
        "path": "/sitecore/layout/Renderings/Project/My Sites/Site-B",
        "allowedPushOperations": "createAndUpdate"
      },
      {
        "name": "B-placeholders",
        "path": "/sitecore/layout/Placeholder Settings/Project/My Sites/Site-B",
        "allowedPushOperations": "createAndUpdate"
      },
      {
        "name": "B-templates",
        "path": "/sitecore/templates/Project/My Sites/Site-B",
        "allowedPushOperations": "createAndUpdate"
      }
    ]
  }
}

Running the below commands will push the content from Repo (Latest files taken from Repo to your local development environment will be pushed to the Sitecore content Tree)

cd .\src\apps\mysites
dotnet sitecore ser push -n local -i Site-A -w
dotnet sitecore ser push -n local -i Site-A

dotnet sitecore ser push -n local -i Site-B -w
dotnet sitecore ser push -n local -i Site-B

I have added parameters in the script mentioned above.

  • -i is include. We can include the “namespace” we want to push or pull
  • -w is “What-If mode” – It shows if there is any conflict before making any actual change. – May be more details on this in next blog.

If I want to get both sites, I can skip the -i parameter and its value. That will execute all *.module.json files from the directory.

Feel free to reach out to me if you want to know more about the serialization.

Conclusion

Serialization in multi-site environments using Sitecore CLI empowers developers to efficiently manage complex configurations. By leveraging JSON files and PowerShell commands, developers can streamline serialization tasks, ensuring consistency and accuracy across multiple sites within XM Cloud.

Happy serializing!