Mechanic
π§βπ» Get Mechanic!
π§βπ§ Task library
π³ Task requests
π¦Ύ Mechanic.dev
Searchβ¦
Introduction
π―
status.mechanic.dev
π
"I need something custom!"
π€
Hire a Mechanic developer
Resources
π§π»
Task library
π
Slack community
π€
Partner directory
Tutorials
Core Concepts
Events
Tasks
Actions
Runs
Interacting with Shopify
Platform
π
Policies
Cache
Email
Events
GraphQL
Integrations
Liquid
Basics
Filters
Keyword literals
Mechanic objects
REST Admin API
Mechanic tags
action
assign
error
log
Liquid console
Shopify
Webhooks
Techniques
Writing a high-quality task
Tagging Shopify resources
Debouncing events
Responding to action results
Working with external APIs
Finding a resource ID
Migrating templates from Shopify to Mechanic
Securing Mechanic webhooks
Monitoring Mechanic
FAQ
Powered By
GitBook
assign
The
assign
tag is a native feature of Liquid. In Mechanic-flavored Liquid, the assign tag is extended to support assigning within
arrays
and
hashes
.
Assignment into arrays and hashes is always by value, never by reference.
"Assignment by value" means that the result of the assignment will never dynamically change.
1
{% assign foo = "bar" %}
2
{% assign x = array %}
3
{% assign x["foo"] = foo %}
4
β
5
{% assign foo = "qux" %}
Copied!
At the end of this example,
x.foo
still contains
"bar"
, even though the value of the original
foo
variable has changed.
Assigning into arrays
Arrays support assignment by index, using integer lookups.
Code
Output
1
{
%
assign x
=
array
%
}
2
{
%
assign x
[
0
]
=
"one"
%
}
3
{
%
assign x
[
x
.
size
]
=
"two"
%
}
4
β
5
{
%
assign the_third_zero_based_index
=
2
%
}
6
{
%
assign x
[
the_third_zero_based_index
]
=
"three"
%
}
7
β
8
{{
x
|
json
}}
Copied!
1
[
"one"
,
"two"
,
"three"
]
Copied!
Assigning into hashes
Hashes support assignment by key, using string lookups.
Code
Output
1
{
%
assign x
=
hash
%
}
2
{
%
assign x
[
"one"
]
=
1
%
}
3
{
%
assign x
[
"two"
]
=
2
%
}
4
β
5
{
%
assign three
=
"three"
%
}
6
{
%
assign x
[
three
]
=
3
%
}
7
β
8
{{
x
|
json
}}
Copied!
1
{
"one"
:
1
,
"two"
:
2
,
"three"
:
3
}
Copied!
Previous
action
Next
error
Last modified
1yr ago
Copy link
Edit on GitHub
Contents
Assigning into arrays
Assigning into hashes