Documentation
Feedback
Guides
Storefront Development

Storefront Development
FastStoreIntegrating your storefront with Headless CMS
Managing content with 'scopes' and 'requiredScopes'

Use 'scopes' and 'requiredScopes' to define which store sections can be added to specific pages, ensuring proper content structure for your store.

scopes and requiredScopes are Headless CMS schema definitions that determine which store sections can be added to specific pages (defined within Content Types).
These features help manage the content structure and ensure store sections are used in appropriate contexts. For example, the Hero component is only available for the home page or pages like the Product Details Page (PDP).

Before you begin

Update the @faststore/core package version

Make sure you have @faststore/core version 3.0.18 or greater to benefit from this feature. If you don't have the updated package, follow the instructions in Updating the @fastore/core package version.

Set Headless CMS

Make sure to have set the Headless CMS files content-types.json and sections.json in your store project by following the Setting up the Headless CMS guide. These files contain the store’s custom Content Types and sections.

scopes

scopes are labels that define the context provided by a Content Type. They help categorize Content Types based on their capabilities.
The scopes are string arrays within the definition of your Content Type in the content-types.json file. For example:

_10
{
_10
"id": "home",
_10
"name": "Home",
_10
"scopes": ["home"],
_10
"isSingleton": true,
_10
"configurationSchemaSets": [...]
_10
}

In this example, the Home Content Type stores content for your home page and has a scopes named home. This scopes definition means that only sections designed for the home page context can be used with this Content Type.

Default FastStore scopes

When creating custom sections, you can restrict their usage to specific Content Types using these default scopes:
scopes nameContent Type
customLanding Page
globalGlobal Sections
landingLanding Page
pdpProduct Details Page
plpProduct Listing Page
searchSearch Page

requiredScopes

requiredScopes defines the Content Types a section can be used in. Similar to scopes, they are specified as string arrays within the section definition in the sections.json file.
A section is only available for a Content Type in Headless CMS if the Content Type scopes include at least one matching scopes from the section's requiredScopes. Sections without any requiredScopes can be used in any Content Type.
In the following example, the ProductShelf section is only available for PDPs:

_10
{
_10
"name": "ProductShelf",
_10
"requiredScopes": ["pdp"],
_10
"schema": {...},
_10
}

Empty requiredScopes

When a section has an empty requiredScopes ([]), the section is available for all Content Types. In the following example, the Navbar section is available to use in any Content Type because it has no required scopes:

_10
{
_10
"name": "Navbar",
_10
"requiredScopes": [ ],
_10
"schema": {...}
_10
}

Default FastStore requiredScopes

When creating custom sections for Headless CMS, you can use these default requiredScopes for specific Content Types:
requiredScopes nameSection name
customCrossSelingShelf
pdpCrossSelingShelf, Breadcrumb, and ProductDetails
plpBreadcrumb and ProductGallery
searchProductGallery

Using scopes and requiredScopes

In the following example, let’s set a new Content Type Custom Page to display a new Call To Action section.
{"base64":"  ","img":{"width":740,"height":285,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":16763,"url":"https://vtexhelp.vtexassets.com/assets/docs/src/scoped-sections-final-result___0b7a9ad190b98753b7a99edec657f3f5.png"}}
To better understand this tutorial, make sure you create the new Call To Action component by following the instructions in the Creating a new section guide.

Setting up the Headless CMS files

Make sure to have set up the Headless CMS files content-types.json and sections.json in your store project by following the Setting up the Headless CMS guide. These files contain the store custom Content Types and sections.
  1. In the content-types.json file, create a new Custom Page Content Type by adding the following:
    content-types.json

    _46
    {
    _46
    "id": "customPage",
    _46
    "name": "Custom Page",
    _46
    "scopes": ["custom"],
    _46
    "configurationSchemaSets": [
    _46
    {
    _46
    "name": "Settings",
    _46
    "configurations": [
    _46
    {
    _46
    "name": "seo",
    _46
    "schema": {
    _46
    "title": "SEO",
    _46
    "description": "Search Engine Optimization options",
    _46
    "type": "object",
    _46
    "widget": {
    _46
    "ui:ObjectFieldTemplate": "GoogleSeoPreview"
    _46
    },
    _46
    "required": ["slug", "title", "description"],
    _46
    "properties": {
    _46
    "slug": {
    _46
    "title": "Path",
    _46
    "type": "string",
    _46
    "default": "/"
    _46
    },
    _46
    "title": {
    _46
    "title": "Default page title",
    _46
    "description": "Display this title when no other title is available",
    _46
    "type": "string",
    _46
    "default": "FastStore Starter"
    _46
    },
    _46
    "description": {
    _46
    "title": "Meta tag description",
    _46
    "type": "string",
    _46
    "default": "A beautifully designed store"
    _46
    },
    _46
    "canonical": {
    _46
    "title": "Canonical url for the page",
    _46
    "type": "string"
    _46
    }
    _46
    }
    _46
    }
    _46
    }
    _46
    ]
    _46
    }
    _46
    ]
    _46
    }

    We defined the "scopes": ["custom"] for the new customPage Content Type. The custom scope is also the landingPage default scope defined in FastStore.
  2. In the sections.json file, add the following:
    sections.json

    _39
    [
    _39
    {
    _39
    "name": "CallToAction",
    _39
    "requiredScopes": ["custom"],
    _39
    "schema": {
    _39
    "title": "Call To Action",
    _39
    "description": "Get your 20% off on the first purchase!",
    _39
    "type": "object",
    _39
    "required": [
    _39
    "title",
    _39
    "link"
    _39
    ],
    _39
    "properties": {
    _39
    "title": {
    _39
    "title": "Title",
    _39
    "type": "string"
    _39
    },
    _39
    "link": {
    _39
    "title": "Link Path",
    _39
    "type": "object",
    _39
    "required": [
    _39
    "text",
    _39
    "url"
    _39
    ],
    _39
    "properties": {
    _39
    "text": {
    _39
    "title": "Text",
    _39
    "type": "string"
    _39
    },
    _39
    "url": {
    _39
    "title": "URL",
    _39
    "type": "string"
    _39
    }
    _39
    }
    _39
    }
    _39
    }
    _39
    }
    _39
    }
    _39
    ]

We defined that the Call To Action section will only be available for customPage and landingPage Content Types.
Remember that the Call To Action section is also available for the landingPage Content Type because the custom scope is default for it in FastStore.
When editing the Custom Page Content Type, the Headless CMS checks its scopes (custom) and matches them against the sections' requiredScopes (custom). Since the Call to Action section matches the Custom Page and Landing Page scope, the section is available to use in these two Content Types.

Syncing the Headless CMS changes

  1. Open the terminal and run yarn cms-sync to sync the new files created in the previous step.
  2. In the VTEX Admin, go to Storefront > Headless CMS, and open the FastStore project.
  3. Click on the Create Document dropdown.
  4. Click on Custom Page:
    {"base64":"  ","img":{"width":1226,"height":823,"type":"gif","mime":"image/gif","wUnits":"px","hUnits":"px","length":434480,"url":"https://vtexhelp.vtexassets.com/assets/docs/src/scoped-sections___9b707a54b4807b9de9bae3e0616d10eb.gif"}}
  5. In the Sections tab, click on Add Section (+).
  6. Select the Call To Action section.
  7. Set the section fields as you wish.
  8. Click Save.
  9. Click Preview to preview the saved content. You will see a section similar to the image below with a title Shop deals in Fashion and a Call To Action button See all deals.
    {"base64":"  ","img":{"width":740,"height":285,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":16763,"url":"https://vtexhelp.vtexassets.com/assets/docs/src/scoped-sections-final-result___0b7a9ad190b98753b7a99edec657f3f5.png"}}
Contributors
1
Photo of the contributor
+ 1 contributors
Was this helpful?
Yes
No
Suggest Edits (GitHub)
Contributors
1
Photo of the contributor
+ 1 contributors
On this page