{{ directory }} not available in parts of menu--main.html.twig Printing {{ directory }} at the start of the file works fine. But a bit further it's no longer availble:

{% import _self as menus %}

{#
  We call a macro which calls itself to render the full tree.
  @see http://twig.sensiolabs.org/doc/tags/macro.html
#}
{{ menus.menu_links(items, attributes, 0) }}

{% macro menu_links(items, attributes, menu_level) %}
    **{{ directory }} {# THIS WORKS #}**
    {% import _self as menus %}
    {% if items %}
        {% if menu_level == 0 %}
            &lt;ul{{ attributes }}&gt;
        {% else %}
            &lt;ul id="navigation"&gt;
        {% endif %}
        {% for item in items %}
        &lt;li class="active"&gt;
            &lt;a href="{{ item.url }}"&gt;
                **{{ directory }} {# THIS DOESN'T WORK #}**
                &lt;img src="{{ directory }}/images/menuicon.png" alt="" /&gt;
                {{ item.title }}
            &lt;/a&gt;
        &lt;/li&gt;
        {% endfor %}
        &lt;/ul&gt;
    {% endif %}
{% endmacro %}


Any idea why this happens and how to fix it?
The second occurrence of {{ directory }} is within a Twig macro. As the Twig documentation mentions, you cannot access the outer variables in a macro:


  But as with PHP functions, macros don't have access to the current template variables.


You can however pass _context through a macro parameter and access directory that way, or pass it explicitly.