07-24-2025 02:04 AM
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 }}
Solved! Go to Solution.
07-24-2025 03:19 AM - edited 07-24-2025 03:19 AM
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 }}
07-24-2025 03:19 AM - edited 07-24-2025 03:19 AM
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 }}
07-28-2025 05:36 PM
Thanks. I always like seeing little things like this.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide