Shopify / Shopify/liquid

Assigning to loop variable fails silently

Open
#905 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
11.9k
Forks
1.5k
Avg merge
17h 55m
Merged PRs (30d)
3

Description

I am using Liquid through Jekyll 3.4.3, so this issue may not be current.

Variables assigned through {% assign %} can be re-assigned through {% assign %} or {% capture %}:

{% assign word = "three" %}{{ word }}
{% assign word = "not a number" %}{{ word }}
{% capture word %}something else{% endcapture %}{{ word }}

Output:

three
not a number
something else

However, variables assigned by {% for %} cannot be re-assigned:

{% assign test = 'one,two,three' | split:',' %}
{% for word in test %}{{ word }}
{% assign word = "not a number" %}{{ word }}
{% capture word %}something else{% endcapture %}{{ word }}
{% endfor %}

Output:


one
one
one
two
two
two
three
three
three

If this is the intended behavior, I would expect it to be documented and to see an error or warning generated when assigning to the (immutable) loop variable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the shown Liquid template to confirm whether loop variables remain immutable when reassigned with assign or capture. Then determine whether the intended result is documented behavior or an error/warning, and verify that the chosen resolution is reflected in the output and documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
jekyll, ruby
Domain
web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.