Skip to content
Log in

Liquid Session Variables

On this page

A session variable is a temporary storage unit that holds data for a user’s session on a website. It retains information fed to it while the user is active on the site and disappears when the session ends. A session usually ends because the browser was closed or the session expired. Liquid session variables allow you to temporarily store information that can be utilized within your Liquid theme.

For instance, you can capture specific user data while they navigate through a particular section of your site. Later, you can use this information to perform personalized actions or display relevant content based on the data gathered from the user.

A key feature of these variables is their accessibility throughout your store. They can be created, updated and retrieved anywhere in the store.

Functionality of Session Variables

Session variables consist of a key and a value. The key helps reference the variable wherever it is intended to be used, while the value represents the data stored in it.

Here’s a simple example of how to set a session variable.

liquid {% session title: "My Store" %}

And here is how you retrieve that value:

liquid {{ session_variables["title"] }}

The output here would be My Store

It is also helpful to note that session variables can store values derived from other variables.

Example where the store is named Acme Store.

liquid {% assign name = current_store.name %} {% session title: name %}

liquid {{ session_variables["title"] }}

Output = Acme Store.

Important Note

These variables are declared within tags, and their results can be accessed using objects. Note that they are declared using session instead of assign.

Was this article helpful?

Was this article helpful?