Sites

Contents

In this chapter, you’ll build a tree structure of your content with a site item at the root, and learn a handy trick for the GraphQL API.

Introduction

Next.XP is built to provide complete control over a website, including landing pages and the URL structure. For this use-case, Content Studio’s tree structure will come in handy.

Task: Create the site

Next.XP needs a root content item. This item will act as the front-page of your site.

Before you continue, clear all selections in the Content Studio list view (this way the site content will be placed on the project root).
  1. Create a new item - Click New in the Content Studio toolbar, then select the Site content type. This opens the content editor in a new tab.

  2. Give the site a name - Fill in a display name for the site. "HMDB" (short for Headless Movie DB) will do fine.

    If you choose a different name, make sure the site path name (seen below the Display name) is set to hmdb, as this is used throughout the tutorial.
  3. Add your app to the site - Select it in the Applications form field and click Apply.

    Sites act as scopes in the content structure. By adding an app to the site, you effectively allow editors to create content based on the app within this scope.

    Your form should now look something like this:

    Give the site a name, and add the Movie DB app
  4. Save the site - Click Save in the toolbar.

    This leaves the item in the In progress state, which is OK for now.

Task: Move content into the site

To quickly get some content and structure within the site, move the Movie DB content into it. Return to the Content Studio tab, and follow these steps:

  1. Select the folders in the list, and click Move in the toolbar.

  2. Select the HMDB site as the target and click Move once more.

    Move the folder into the site
  3. Mark the site as ready - Select the site (root item) in the tree structure, and click Mark as ready in the top right. This marks the item as ready and opens the Publishing Wizard.

    Mark as ready
  4. Publish the entire tree structure - Toggle Include child items, click Apply in the wizard header, then click Publish now.

    Publish entire tree structure
  5. Verify the result - The content tree now shows the folders beneath the HMDB site, and the items are published.

Task: Run queries in the site context

In GraphQL queries, you may use a so-called "site context". This is achieved by selecting your site with the scopeKey parameter of the guillotine field.

  1. Specify the scopeKey parameter - Back in Query Playground, add the scopeKey parameter to your previous query, and set it to the path of your site:

    query($path:ID!){
      guillotine(project: "intro", scopeKey: "/hmdb") {
        ...
      }
    }
    scopeKey can be either a path or a content ID. A benefit of using the site’s ID is that you can change its name and path without affecting your queries.

    Without scopeKey, URLs are project-relative and getSite returns null. Scope selects the context for URLs, macros and image styles; it does not restrict searches to a subtree. Add explicit path conditions to DSL queries when needed. Page URLs for content outside the selected scope produce a field error.

  2. Run a query with the site context - One of the new features you get from the site context is the ${site} placeholder, which can be used in paths. Update your query variables as follows, and run the movie query from the previous chapter once more:

    {
        "path": "${site}/movies/s7ven"
    }
  3. Verify the result - The response contains the same movie as before. Here, ${site} resolves to the path of the site, so the full path expands to /hmdb/movies/s7ven.

Summary

You’ve created the HMDB site, moved the sample content into it and published the tree. You’ve also used scopeKey and the ${site} placeholder to run queries in the context of the site.


Contents

Contents