Skip to content

Can not use imports from within call-block of another imported macro #507

@seijikun

Description

@seijikun

Describe the bug
The call-block of an imported macro is unable to use the other imports - because instead of looking at the call-side's import context, it searches for the imports in the file that it was imported from.

To Reproduce
repro.tar.gz

File section.jinja:

{% macro render(title) %}
    <section>
        <h1>{{title}}</h1>
        <div>{{caller()}}</div>
    </section>
{% endmacro %}

File element.jinja:

{% macro render() %}
    <div class="myElement">{{caller()}}</div>
{% endmacro %}

Root template (page.jinja):

{% import "section.jinja" as section %}
{% import "element.jinja" as element %}

{% call section::render("sectiontitle") %}
    {# the element scope is not found because it's looking in section's import context #}
    {% call element::render() %}
        elementcontent
    {% endcall %}
    sectioncontent
{% endcall %}

Workaround
A dirty hack to workaround this, is to add the same element import in the section.jinja file.

Askama version
7610b37

Rust version
rustc 1.90.0-nightly (b03b3a7ec 2025-06-26)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions