Skip to content

include without context doesn't work in macro #2108

@dseomn

Description

@dseomn

When I use include ... without context inside a macro like this:

import jinja2

print(
    jinja2.Environment(
        loader=jinja2.DictLoader(
            {
                "included": "foo",
                "main": """
                    {%- macro foo() %}
                        {%- include "included" without context %}
                    {%- endmacro %}
                    {{- foo() -}}
                """,
            }
        ),
    )
    .get_template("main")
    .render()
)

The macro evaluates to something that looks like a repr() string instead of the contents of the included template:

$ python3 foo.py 
<generator object root.<locals>.macro at 0x7f79f60a0580>

The same include line works outside of a macro, and it works inside the macro if I remove without context:

$ python3 foo.py 
foo

Environment:

  • Python version: 3.13.5
  • Jinja version: 3.1.6-1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions