Skip to main content

SitecoreAI · Tutorial

Building Your First Sitecore XMC Component, End to End

From data template to rendered page: the Content Editor half of building a component, step by step.

GavAusWeb2 min read

Building your first component in Sitecore XMC feels unfamiliar coming from React/Next.js alone, because half the work happens in the Content Editor, not your IDE. Here's the end-to-end flow to get a component from template to rendered page.

Build the componentLink to this section

  1. Step 1: Create the data template

    In the Content Editor, go to Templates and create a new template for your component (right-click › Insert › New Template). This defines the shape of the content your component will consume — think of it as your component's props schema, but authored in Sitecore rather than TypeScript.

  2. Step 2: Add the fields

    Add fields to that template matching what your component needs. If you add an Image field, set its source to query:$siteMedia so editors get scoped to the site’s media library instead of the entire media tree.

  3. Step 3: Create the rendering item

    Create the rendering item under Layout › Rendering › Project › [Your Site], following the existing pattern for an XMC JSON Rendering.

  4. Step 4: Connect the datasource

    Point the rendering at your new datasource template (the one you just built).

    Set 'IsAutoDatasourceRendering' to true if you want Sitecore to automatically create a datasource item the first time the rendering is added to a page — skip this and editors will have to create the datasource by hand every time.

    Also wire up Layout Service › Rendering Contents Resolver to 'Datasource Resolver' so the datasource template is actually applied.

  5. Step 5: Add it to a page

    Once that's saved, add the rendering to a page's placeholder (e.g. headless-main) via Presentation › Final Layout › Edit › Controls, assign the matching datasource, and you should see your component render with real content.