You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 12, 2023. It is now read-only.
I'm seeing some strange behavior with variable assignments within a simple for loop. Here is version 1 of my code, which works as expected:
{% assign isThree = 'initial value' %}
{% for i in (1..9) %}
{% if i == 3 %}
{% assign isThree = true %}
{% else %}
{% assign isThree = false %}
{% endif %}
<p>{{ i }}: {{ isThree }}</p>
{% endfor %}
Basically, it loops through the numbers 1 through 9, and displays each one, along with a boolean indicating whether or not the number is three. This produces the expected output:
And here's version 2 of my code, which exhibits the strange behavior in question. It's identical to version 1, except it now assigns a variable named someOtherVar before assigning isThree:
{% assign isThree = 'initial value' %}
{% for i in (1..9) %}
{% assign someOtherVar = 'foo' %}
{% if i == 3 %}
{% assign isThree = true %}
{% else %}
{% assign isThree = false %}
{% endif %}
<p>{{ i }}: {{ isThree }}</p>
{% endfor %}
This change shouldn't affect the output at all, but it does! In effect, it makes it so that values assigned to isThree aren't available until the next iteration of the loop:
This is possibly a bug in liquid-node, but I'm observing it in grunt-liquid, so I'm reporting it here...
The issue is described in this Stack Overflow question. I'll reproduce the details below.
I'm seeing some strange behavior with variable assignments within a simple for loop. Here is version 1 of my code, which works as expected:
Basically, it loops through the numbers 1 through 9, and displays each one, along with a boolean indicating whether or not the number is three. This produces the expected output:
And here's version 2 of my code, which exhibits the strange behavior in question. It's identical to version 1, except it now assigns a variable named someOtherVar before assigning isThree:
This change shouldn't affect the output at all, but it does! In effect, it makes it so that values assigned to isThree aren't available until the next iteration of the loop:
If I move the someOtherVar assignment below the {% if %} block, then everything works fine again.
The text was updated successfully, but these errors were encountered: