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). |
-
Create a new item by clicking
Newin Content Studio toolbar, then select theSitecontent type. This will open the content editor in a new tab. -
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. -
Add your app to the site - by selecting it in the
Applicationsform field and clickingApply.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. 
When completed, your form should look something like this, and you can now press
Savein the toolbar.This will leave the item in In progressstate, 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:
-
Select the folders in the list, and click
Movefrom the toolbar. -
Selecting the
HMDBsite as the target and clickMoveonce more.
-
Wrap up by publishing the changes. Select the site (root item) in the tree structure, and click
Mark as readyin the top right. This marks the item as ready and opens the Publishing Wizard.
-
To publish the entire new tree structure toggle
Include child items, clickApplyin the wizard header, then clickPublish now.
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.
-
Specify
scopeKeyparameterBack in Query Playground, add the
scopeKeyparameter to your previous query, and set it to the path of your site:query($path:ID!){ guillotine(project: "intro", scopeKey: "/hmdb") { ... } }scopeKeycan 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 andgetSitereturnsnull. 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. -
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.