Developers · Liquid
Liquid Objects: Insites
Last updated 7 November 2026
context
TheThis section discusses the following topics:
- context.authenticity_token
- context.constants
- context.cookies
- context.current_user
- context.device
- context.environment
- context.flash
- context.headers
- context.is_xhr
- context.language
- context.location
- context.modules
- context.page
- context.params
- context.session
- context.useragent
- context.visitor
context.authenticity_token
context.constants
context.cookies
context.current_user
context.device
context.environment
A common use case for this object is hiding certain functionalities in production without blocking the release.
context.flash
The value for each key is a message string. Flash messages are set on form submissions.
context.headers
context.is_xhr
: for non-XHR requests : for XHR requests
An XHR request is identified by checking if the value of the
context.language
context.location
Example 1: Extracting params from path name
This example extracts parameters from the path name using
Sample URL:
{% liquid
assign template = '/app/admin/content/{city}/{area}/{street}'
assign params = context.location.pathname | extract_url_params: template
%}
{{ params.city }} => nyc
{{ params.area }} => brooklyn
{{ params.street }} => main
The street is {{ params.street }}Example 2: Conditional list class
<li class='{% if context.location.href contains link.href %}active{% endif %}'>
<a href='#'>{{ link.name }}</a>
</li>context.modules
Example: List all properties for installed modules
<section>
{% for module in context.modules %}
Module name: {{ module[0] }}
<table>
<tbody>
{% for properties in module[1] %}
<tr>
<th> {{ properties[0] }} </th>
<td> {{ properties[1] }} </td>
</tr>
{% endfor %}
</tbody>
</table>
{% endfor %}
</section>context.page
Available attributes:
{{ context.page }}{{ context.page.id }} => 1
{{ context.page.slug }} => foo
{{ context.page.layout }} => application
{{ context.page.metadata }} => {}context.params
- Including form data in notifications
- Form data manipulation through
- Data validation in authorization policies
Example: site path params mapping
When visiting the page with path
{{ context.params.slug }} => app
{{ context.params.slug2 }} => admin
{{ context.params.slug3 }} => content
{{ context.params.slugs }} => nyc/brooklyn/mainPlease note that another way that you can use to extract page parameters is by using Example 1 of context.location.pathname.
context.session
A browser initiates a session by generating a unique
context.useragent
Example: Displaying useragent
{{ context.useragent }}Result:
context.visitor
Exposing a local variable within the context object
To broaden the scope of a defined local variable, making it accessible outside its current file, you must promote it to the global
{% liquid
assign foo = 'bar'
export foo, namespace: 'baz'
%}
{{ context.exports.baz.foo }}