Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird behavior with duplicate variable names #911

Open
ctron opened this issue May 5, 2024 · 1 comment
Open

Weird behavior with duplicate variable names #911

ctron opened this issue May 5, 2024 · 1 comment

Comments

@ctron
Copy link

ctron commented May 5, 2024

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.

@Keats
Copy link
Owner

Keats commented May 5, 2024

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

Hu weird, it shouldn't?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants