Kickstart XM Cloud Journey with Sitecore Content SDK

The Sitecore Content SDK enables developers to build front-end applications that connect directly to content hosted in XM Cloud. In this post, we’ll walk through how to set up your local environment, connect to an XM Cloud instance, and get your first Content SDK app running locally.


Prerequisites

Before we start, make sure you have:

  • Access to an XM Cloud instance
  • Visual Studio Code installed
  • The latest version of Node.js installed

You can verify your Node.js installed version by running following command:

node -v
A black background with white text

AI-generated content may be incorrect.

Create a New App Folder

Let’s create a folder for our app.
You can name it anything, for example:

mkdir ContentSDKDemoApp
cd ContentSDKDemoApp

Create a New Content SDK App

Run the following command to download and initialize a starter Content SDK template:

npx @sitecore-content-sdk/create-sitecore-jss nextjs

You’ll be prompted to confirm the app location, type y to proceed.

Next, it will ask you to select between SSG (Static Site Generation) or SSR (Server-Side Rendering):

·       Choose SSG for static sites

·       Choose SSR if your components require dynamic rendering

For this demo, we’ll select SSG.

A screenshot of a computer

AI-generated content may be incorrect.

A screen shot of a computer

AI-generated content may be incorrect.

Once complete, you’ll have a Next.js app created in your chosen folder.

 A screenshot of a computer

AI-generated content may be incorrect.

Install the Content SDK CLI

The Content SDK CLI provides useful commands to create components and manage your Content SDK applications.

To install it globally:

npm install -g @sitecore-content-sdk/cli
A screen shot of a computer

AI-generated content may be incorrect.

After installation, open your new app in Visual Studio Code. You’ll notice several environment files (like .env.example) already created.

A screenshot of a computer

AI-generated content may be incorrect.

Set Up Environment Variables

We’ll now configure the environment connection to your XM Cloud instance.

1.      Duplicate one of the existing .env files (for example .env.remote.example)

2.     Rename it as .env.local

A screenshot of a computer program

AI-generated content may be incorrect.

We’ll fill this file with values from the XM Cloud portal.

Connect to XM Cloud Instance

1.  Log in to your XM Cloud portal:
https://portal.sitecorecloud.io/

A screenshot of a login form

AI-generated content may be incorrect.

2.   Select your project.

A screenshot of a video game

AI-generated content may be incorrect.

3.   Click Manage Environments

A white rectangular object with black text

AI-generated content may be incorrect.

4.   Choose the desired environment

A white background with blue lines

AI-generated content may be incorrect.

5.   Go to the Developer Settings tab and Select your site name, note the

o   SDK VersionContent SDK

o   Environment variables

A screenshot of a computer

AI-generated content may be incorrect.

Copy all environment variable values and paste them into your .env.local file at respective places.

Build and Run the App

Once the .env.local file is configured, run:

npm run build

If you encounter errors, double-check your environment variable values from the XM Cloud portal and update them as needed.

A screenshot of a computer

AI-generated content may be incorrect.

Save the file and run the build again

A screen shot of a computer

AI-generated content may be incorrect.

When the build succeeds, start your app locally with:

npm run start
A screen shot of a computer

AI-generated content may be incorrect.

You’ll see a local URL in the terminal, open it in your browser to view your app.

You’ve now successfully connected your local app to Sitecore XM Cloud using the Content SDK!

In the next post, we’ll explore how to create your first component using the Content SDK and integrate it into this app.

Happy coding!

Comments

Popular posts from this blog

Beginner’s Guide: Step-by-Step Local Installation for Sitecore XM Cloud

Setting Up Sitecore Headless with Next.js in Disconnected Mode

Migrating from Sitecore JSS SDK to Content SDK – Best Practices and Pitfalls