Setting a variable in HubL

I am not sure if this is by design or a bug in your implementation but it certainly does not seem to be consistent. I have narrowed it down. The below snippet works as expected:

{% set queryparam2 = "initial" %} {% if 1 == 1 %} {% set queryparam2 = queryparam2 ~ "&type=111" %} {% endif %} {{queryparam2}}

Above prints “initial&type=111” as expected, meaning one can change a variable’s value inside an if block. However, introducing a for loop:

{% set queryparam2 = "initial" %} 
{% if 1 == 1 %} 
 {% set queryparam2 = queryparam2 ~ "&type=111" %} 
 {% for part in [1] %}
 {% set queryparam2 = queryparam2 ~ "&type=222" %} 
 {% endfor %} 
{% endif %} 

{{queryparam2}}

Above prints “initial&type=111” which is NOT as expected, it should be “initial&type=111&type=222”, meaning one can NOT change a variable’s value inside a for block and access it outside that block, even with the variable defined outside the scope of the for block. Comments?

It’s a known limitation. Variables within a for loop are only accessible within the for loop.

Can you explain what you are trying to do? Maybe there is a workaround.

Thanks for the info. That is what I thought.

I did implement a workaround but it does make life a bit harder.