π‘Data Variables
Data Variables enable the definition and use of a value throughout the page.
Hint: CSS Variables are different than Data Variables. They enable the reuse of values in the Style Panel.
Data Variables are defined on any instance in the navigator such as Global Root, Body, or Heading. Variables can be found on the right panel in the settings tab.

Variable scope
Variables are available within the instance they are defined on and any of its children. They are not available in the parent.
If you define a variable on the Global Root, it will be available on all pages and can be used within Slots.
To access variables in the Page Settings, the variable must be defined on the Body of the page.
Global Data Variables
Variables defined on the Global Root are accessible across all pages in your project. This is powerful for:
Reusable contact information β Define your email, phone, or address once and use it everywhere
Site-wide settings β Store company name, social links, or other global data
CMS configuration β Set up API endpoints that all pages can access
Slot compatibility β Global variables work within Slots, enabling dynamic content in reusable components
Setting Up Global Variables
In the Navigator, select Global Root (above Body)
In the Settings panel, add a new variable
Choose the variable type (String, JSON, Resource, etc.)
The variable is now accessible on any page
Use Cases
Contact email: Define once, bind to all contact forms and footers
Simple CMS: Use JSON variables on Global Root for site-wide data that displays in Slots
API keys: Store Resource configurations globally for consistent data fetching
Variables
System
System variable is a unique variable in that it exists by default, while all other variables are added by the user.
System variable contains the following:
Params β Key/value pairs that are defined in Dynamic Page URLs.
Search β Key/value pairs of query parameters that may exist in the URL.
Origin β The URL of the current site. It will display whatever the actual URL is, so in the builder, it will be the internal wstd.io domain, but on the published site, it will be the current origin, likely a custom domain.
Pathname β The current page's path (e.g.,
/blog/my-post). Useful for conditional logic based on the current URL.
String
A String variable holds text data, which can be used for content like titles, descriptions, and labels.
Number
A Number variable stores numeric values, including integers and decimals. It's useful for calculations, counters, and any numeric data that components might need to display or use in logic.
Boolean
A Boolean variable represents a true or false value. It is ideal for toggling states, such as visibility.
JSON
A JSON variable allows for structured data in JSON format. It is ideal for creating simple data structures used with Collections to iterate over each item, such as creating a dynamic gallery.
Resource
A Resource variable gets its value from a fetch request, allowing data from a remote system to be used within Webstudio. For example, Resource can be used to interact with a REST API. While it can also be used to interact with a GraphQL API, itβs recommended to use the GraphQL Resource instead.
There are several fields available to configure the fetch request.
Shortcut: The URL field supports pasting in a cURL command. Doing so will automatically populate the various fields within the Resource. Many API docs will provide you with a cURL command, so look out for it to save time.
Copy & Paste: Resources can be copied and pasted between projects. Select an instance with a Resource variable defined, copy it, and paste into another project β the Resource configuration will be included.
URL β Where the resource is located.
Method β A request method. Refer to the third-party API docs to find the suitable method.
Search Params - Key/value pairs used for providing additional parameters as part of the URL. Values can be bound to other variables.
Cache Max Age allows you to define your own cache lifetime.
Headers β Key/value pairs such
Content-Type application/json. Refer to Request Headers for more info.
The requests, including any sensitive secrets like API keys, are handled on the backend and are never exposed to the client.
Response
Once the Resource fetches data, you'll use the Expression Editor to bind data from the response to your website. See Binding for more information.
Caching
You may be wondering whether every visit to your blog results in an API call to your CMS or if the content is cached in Webstudio.
When you configure a Resource, the data is fetched using Cloudflare Workers, which has a built-in caching system.
By default, several factors determine what gets cached and for how long, but one of the primary factors is what the origin system instructs the requesting entity to cache. In other words, the headless CMS tells Cloudflare Workers what can be cached, if anything, and for how long. If you set a custom Cache Max Age value, it will define your cache lifetime instead of relying on API response headers.
Webstudio sees approximately 45% of sub-requests (i.e., fetches from Cloudflare Workers) served from the cache. This means that, on average, roughly half of the time someone visits a page that uses Resources, such as a blog post, the request will go through to the origin/CMS.
GraphQL
A GraphQL Resource variable gets its value from a GraphQL API, allowing data from a remote system to be used within Webstudio. While similar to Resource, itβs unique in that the available fields are specifically designed for interacting with GraphQL APIs.
There are several fields available to configure the fetch request.
URL β Where the resource is located.
Query β A GraphQL query.
Variables β A JavaScript object containing variables that will be passed into the request. This is commonly used to pass in parameters in a URL within a Dynamic Page. For example
{ slug: system.params.slug }See System Variable for more info.
The requests, including any sensitive secrets like API keys, are handled on the backend and are never exposed to the client.
System Resource
A System Resource variable gets its value from internal data.
Available system resources:
Sitemap β Contains data about the static pages on the website, commonly used to build a custom sitemap that combines dynamic data with static data. Refer to the XML Node component for more info.
Current Date β Returns the current date/time, useful for displaying "today's date" or calculating relative times. Can be formatted using the Time component.
Related
Expression Editor β Bind variables to components and create expressions
CMS β Use Resources to fetch content from external systems
Collection β Iterate over JSON or Resource data
CSS Variables β Define reusable style values (different from Data Variables)
Slot β Access global variables in reusable components
Last updated
Was this helpful?
