Reputation: 65046
Are variables set in Jekyll {% include %}
files global in scope? That is, do they leak into the page that included then and subsequent includes?
For example, I have an include file with the following contents:
{% assign ai__attributes = "" %}
{% if include.width %}
{% capture ai__attributes %}{{ ai__attributes }}width="{{include.width}}" {% endcapture %}
{% endif %}
{% if ai__attributes != "" %}
{% capture ai__ial %}{:{{ai__attributes}}}{% endcapture %}
{% endif %}
{{ai__ial}}
This sets teh ai__ial
variable if include.width
has been set. If I call this once with width
set, and then again with it inset, will the ai__ial
from the first call leak into the second? Is there any way to avoid this, e.g., by scoping the variable?
Upvotes: 0
Views: 78
Reputation: 52829
No way to set a local variable, but you can reset ai__ial
in your include.
{% assign ai__attributes = "" %}
{% assign ai__ial = "" %}
...
Upvotes: 2