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

Nested macro call with caller() misses context #1469

Open
LeaVerou opened this issue Jul 1, 2024 · 1 comment
Open

Nested macro call with caller() misses context #1469

LeaVerou opened this issue Jul 1, 2024 · 1 comment

Comments

@LeaVerou
Copy link

LeaVerou commented Jul 1, 2024

Sorry for the poor description, I couldn’t figure out a better one.

Testcase:

{% macro page() %}
<section class="page">
	{{ caller() | safe }}
</section>
{% endmacro %}

{% macro test_page() %}
{% set page_content = 'foobar' %}
{% call page() -%}
	{{ page_content | safe }}
{%- endcall %}
{% endmacro %}

{{ test_page() | safe }}

Should produce:

<section class="page">
	foobar
</section>

Instead produces:

<section class="page">
	
</section>

Jinja2 gets it right btw.

@DmitrySharabin
Copy link

DmitrySharabin commented Jul 1, 2024

To add to @LeaVerou's comment, if we move {% set page_content = 'foobar' %} inside the call block, it produces the expected result:

{% macro page() %}
  <section class="page">
    {{ caller() | safe }}
  </section>
{% endmacro %}

{% macro test_page() %}
  {% call page() -%}
	{% set page_content = 'foobar' %}
	{{ page_content | safe }}
  {%- endcall %}
{% endmacro %}

{{ test_page() | safe }}

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