cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
58
Views
0
Helpful
1
Replies

Reuse CLI Template Variables outside for loop

Tobias Heisele
Level 1
Level 1

Hi Community,

is it possible to reuse a Variable that has been set inside a for loop after the loop ended?

{% for interface in __interfaces %}
  {% if something matches %}
    {% set MyVariable = "This is a Test" %}
  {% endif %}
{% endfor %}

{{ MyVariable }}

1 Reply 1

Tobias Heisele
Level 1
Level 1

Got it (thx to stackoverflow) using a global dictionary

{% set global = {} %}
{% for interface in __interfaces %}
  {% if something matches %}
    {% set _ = global.update({MyVariable:"This is a Test"}) %}
  {% endif %}
{% endfor %}

{% set MyVariable = global["MyVariable"] %}
{{ MyVariable }}