Sites

Contents

In this chapter, you’ll build a tree structure of your content, with a site item at the root + learn about 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: Creating 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 by clicking New in Content Studio toolbar, then select the Site content type. This will open the content editor in a new tab.

  2. Give the site a name by filling 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 will be used throughout the tutorial.
  3. Add your app to the site - by selecting it in the Applications form field and clicking Apply.

    Sites acts 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.

    content studio create site

    When completed, your form should look something like this, and you can now press Save in the toolbar.

    This will leave the item in In progress state, which is ok for now.

Add content

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

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

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

    content studio move

  3. Wrap up by publishing the changes. 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.

    content studio mark as ready

  4. To publish the entire new tree structure toggle Include child items, click Apply in the wizard header, then click Publish now.

    content studio publish

Sweet, you should now have a site with content and a basic tree structure.

Task: Site contextual queries

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 query.

  1. Specify 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"
}
Here, ${site} will resolve to the path of the site and expand - in this case the full path will be expanded to /hmdb/movies/s7ven.

Coming up - get your your Next.js developer environment up and running.


Contents

Contents