Context Variable

Last updated on April 06, 2026.

The variable is a globally accessible object available in every Liquid template: pages, layouts, partials, authorization policies, and notifications. It gives your code access to request data, the current user, session state, environment information, and more.

Inspecting the Context Object

During development, you can output the entire context object on a page to inspect its structure:

Context Components

context.params

Contains all HTTP request parameters, including URL query strings, form data, and named route parameters. For example, returns the value of the named parameter in the page's slug.

context.current_user

Returns the currently logged-in user's basic data: , , , , and . Returns if no user is logged in.

context.session

A key-value store for the current user's session. Use it to persist data across requests (e.g., shopping cart contents, wizard progress). Set values with the Liquid tag.

context.constants

Provides access to sensitive data like API keys, tokens, and secrets. Constants are hidden from output for security. You must access them explicitly via . Set constants using the GraphQL mutation or via the CLI.

context.location

Contains information about the current URL:

  • - full URL of the current request
  • - domain name
  • - URL path without query string
  • - query string

context.headers

Contains HTTP request headers. Use this to check content types, authorization tokens, or custom headers sent by the client.

context.page

Contains information about the current page, including its metadata. Access custom metadata via .

context.environment

Returns the current environment type. Use this to conditionally render content or enable features based on whether you are on staging or production.

context.authenticity_token

The CSRF token populated by the server. Include it in all non-GET form submissions to prevent cross-site request forgery attacks. It is automatically included when using the form tag.

context.cookies

Returns an object containing all cookies for the current site.

context.device

Returns information about the visitor's device, including device type detection (mobile, tablet, desktop).

context.flash

Contains flash messages set during form submissions or redirects. Flash messages persist for one request and are commonly used to display success or error notifications.

context.is_xhr

Returns if the current request is an AJAX (XMLHttpRequest) request. Useful for returning different responses for AJAX vs. regular page loads.

context.language

Returns the current language code for the request. Used with the translation system to determine which language to render.

context.modules

Provides access to installed module information.

context.useragent

Returns the raw User-Agent string from the request headers.

context.visitor

Returns visitor-level information, typically used for analytics and tracking.

Have a suggestion for this page?

Didn't quite find what you are looking for or have feedback on how we can make the content better then we would love to hear from you. Please provide us feedback and we will get back to you shortly.