tera icon indicating copy to clipboard operation
tera copied to clipboard

Weird behavior with duplicate variable names

Open ctron opened this issue 1 year ago • 1 comments

In a zola project I had the following:

{% set pages = get_section(path="projects/_index.md") %}
{% for page in pages.pages %}
<li><a class="link-body-emphasis" href="{{ page.path | safe }}">{{ page.extra.menuLabel | default(value=page.title) }}</a></li>
{% endfor %}

The result was was all of those menu entries had the extra.menuLabel of the current page. Not of the page from the for loop.

I quickly figured out that page was a global variable and that renaming the for loop page to something different solved the issue.

However, I found it weird that a missing page.extra.menuLabel would fall back to the global page variable. My expectation would have been that the page variable from the for loop would override the full object/struct of page. Or, would raise a conflict of a duplicate name. But not "mix" those structs.

ctron avatar May 05 '24 09:05 ctron

However, I found it weird that a missing page.extra.menuLabel would fall back to the global page variable

Hu weird, it shouldn't?

Keats avatar May 05 '24 18:05 Keats