fabpot/Twig — Issue #651: Child template's macro imports don't override those of parent
Author: jmikola
Created: 2012-02-29 21:11:06+00:00
State: open

Let's say I have the following macro templates:

```jinja
{# filename:childMacros.html.twig #}

{% macro foo() %}
FOO
{% endmacro %}
```

```jinja
{# filename: parentMacros.html.twig #}

{% macro bar() %}
BAR
{% endmacro %}
```

I also have a child template that extends a parent:

```jinja
{# filename: child.html.twig #}
{% extends "parent.html.twig" %}
{% import "childMacros.html.twig" as macro %}

{% block content %}
{{ macro.foo() }}
{% endblock %}
```

```jinja
{# filename: parent.html.twig #}
{% import "parentMacros.html.twig" as macro %}

{% block content %}{% endblock %}
```

When rendering the child, I receive a Twig_Error_Runtime exception stating:

> Method "foo" for object "__TwigTemplate_c5f32e3601a3106fa6a99f6f8f2a9008" does not exist in "child.html.twig" at line 6

Peaking into the cached template, it appears that it actually contains the compiled code for `parentMacros.html.twig`. It seems like the parent's import statement and alias is preventing the child's import from functioning. I don't believe this behavior is documented, but is it intentional?