The Assign Tag
  • 04 Apr 2025
  • 1 minute read
  • Dark
    Light
  • PDF

The Assign Tag

  • Dark
    Light
  • PDF

Article summary

In Liquid markup, the assign tag creates or updates an array name associated with an export.

This gives you the freedom to use the original naming convention or the new array name, without having to create more query exports. Think of assign as a label or a note that you can reference later on.

Here’s an explanation by way of a non-Slate example:

  • Imagine you have 12 Slate Sharks and you want to remember that you have 12 Slate Sharks.

  • You might write down “Slate Sharks = 12” on a sticky note.

  • Later when you’re deciding how many Slate Sharks to give away, you can look at your note to see how many you have.

How to use assign

The assign tag has the following syntax:

{% assign academic_array = {{academic_interests}} | split: "," %}
  • Here we have an export, academic_interests—a string containing a list of academic interests.

  • Using the split filter, we delimit each value with a comma.

  • From there, those values are assigned to a new variable named academic_array. This new array name can be used to iterate over or reference each interest individually.

This example can target single values in multi-value fields to render, for example, academic interest information in Content Blocks:

{% assign academic_array =  {{academic_interests}} | split: ',' %}
{% for aca_interest in academic_array %}
    {{aca_interest | snippet: "Academic Majors"}}
{% endfor %}

Why use assign?

Consistent value storage

The assign tag allows you to store values that might need to be consistently referenced. Assign allows for adjustment of the actual value without adjusting the actual export.

Simplification

assign simplifies Liquid markup and promotes an additional layer of organization.

Liquid markup can get complex over time. The assign tag allows for a consistent naming convention beyond the query.

Avoids repetition

A singular export can be reused and edited multiple times without the need for multiple similar exports in your queries.

📖 Further reading: See the Shopify documentation on the assign tag.


Was this article helpful?