CMS Development

wnell
Participante

Setting a variable in HubL

resolver

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?

0 Avaliação positiva
1 Solução aceita
ndwilliams3
Solução
Conselheiro(a) de destaque

Setting a variable in HubL

resolver

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

Exibir solução no post original

0 Avaliação positiva
3 Respostas 3
ndwilliams3
Solução
Conselheiro(a) de destaque

Setting a variable in HubL

resolver

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

0 Avaliação positiva
ndwilliams3
Conselheiro(a) de destaque

Setting a variable in HubL

resolver

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

0 Avaliação positiva
wnell
Participante

Setting a variable in HubL

resolver

Thanks for the info.  That is what I thought.

 

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

0 Avaliação positiva