Tailwind Logo

Adding a Site to XM Cloud

XM Cloud

Published: 2023-12-20

We have been using the default Basic Site contents to check the operation, but this time we will create a new blank site and check the procedure to link it with the new Next.js project.

Create a new site

If a site has already been created and you wish to add a new site, click on the Create website button in the upper right corner.

createwebsite01.png

Clicking on the "Template" button will take you to the template selection screen as shown in the screen below. In this case, we will select Empty Site.

createwebsite02.png

Then specify a name for the site.

createwebsite03.png

Click and wait a few minutes for a sample site to be created.

createwebsite04.png

Open Pages and you will see that an empty site has been created. For now, we will place the Title component in Main.

createwebsite05.png

Publish your site

Since we have added a new site, we will first publish the necessary data. This time, from the XM Cloud Deploy screen, execute Publish all sites.

createwebsite06.png

Create a new Next.js project

We will add a new Next.js project. The procedure is the same as when setting up a site on Netlify.

This time, add a project named xmc-tailwind under src.

createwebsite13.png

If you create a new one, you will need to remove the .git folder, as git init will be executed when it is added directly on the command line.

createwebsite14.png

The new project has now been added, and is shown below in VS Code.

createwebsite15.png

Copy the .env file included in the new project you created as .env.local and obtain and set the following values from XM Cloud

  • SITECORE_API_KEY
  • SITECORE_API_HOST
  • GRAPH_QL_ENDPOINT
  • JSS_APP_NAME ( same as the name of the site, this time xmc-tailwind )
  • DEFAULT_LANGUAGE (Set en)

Now that the above values have been set, accessing Sitecore with jss start:conntected will allow you to view the page using the published data.

createwebsite07.png

The new site can now be referenced by additional applications.

Deploy to Vercel

To deploy the newly created Next.js, create another new project in Vercel. The difference from the site already deployed is in the form of a different root directory path.

createwebsite08.png

Also, since JSS_APP_NAME is a different app name, we will change it for Environment Variables and proceed. After a few moments, the site will be up and running.

createwebsite09.png

Fine-tuning the SXA site

For the Sitecore configuration in the case of multiple sites, the hostname part needs to be changed since both hostnames will be *. First, let's assume that the first site is sitecoredemo-jp in this case.

createwebsite10.png

Set the Hostname for the other site. Then, from the Desktop Tools in Administration, click on PowerShell Toolbox and open SXA Site Manager.

createwebsite11.png

If no errors are displayed as shown below, you can use the system without any problems.

createwebsite12.png

Create serialization definitions

To manage the data for the new site as well, the following files were created under src. First, the code for the Tailwind.module.json file, which is module-related.

JSON
{
    "namespace": "Tailwind",
    "items": {
      "includes": [
        {
          "name": "tw-placeholders",
          "path": "/sitecore/layout/Placeholder Settings/Project/xmc-tailwind"
        },
        {
          "name": "tw-component-renderings",
          "path": "/sitecore/layout/Renderings/Feature/Tailwind"
        },
        {
          "name": "tw-component-settings",
          "path": "/sitecore/system/Settings/Feature/Tailwind"
        },
        {
          "name": "tw-component-branches",
          "path": "/sitecore/templates/Branches/Feature/Tailwind"
        },
        {
          "name": "tw-component-template",
          "path": "/sitecore/templates/Feature/Tailwind"
        },
        {
          "name": "tw-renderings",
          "path": "/sitecore/layout/Renderings/Project/xmc-tailwind"
        },
        {
          "name": "tw-templates",
          "path": "/sitecore/templates/Project/xmc-tailwind"
        }
      ]
    }
  }

Next, create the file TaindindContent.module.json as a content-related file.

JSON
{
    "namespace": "Tailwind-Content",
    "references": ["Tailwind"],
    "items": {
      "includes": [
        {
          "name": "tw-content",
          "path": "/sitecore/content/xmc-tailwind"
        },
        {
          "name": "tw-media",
          "path": "/sitecore/media library/Project/xmc-tailwind"
        }
      ]
    }
  }

This completes the configuration. Please use the following command to perform serialization.

PowerShell
dotnet sitecore ser pull -n development

When you run it, you will see that the data has been created in a folder named tw.

createwebsite16.png

Summary

In this article, we showed the process of creating a new site, a new project, and deploying it in Vercel, confirming that instead of creating an XM Cloud project for each site, a single XM Cloud can be used to configure multiple sites.

Tags