Twig: Globals in a "with" block

Created on 26 Jan 2017  Â·  4Comments  Â·  Source: twigphp/Twig

In Symfony, writing:

{% with {} only %}
    {{ app.request.attributes.get('_route') }}
{% endwith %}

leads to a Variable "app" does not exists.

Looks like global Twig variable are not accessible in a with block, maybe they should?

Bug

Most helpful comment

@HeahDude yes they are. But this is quite inconsistent with {% include ... only %} and {% embed ... only %} where global variables are still available

All 4 comments

The globals should be available if you remove only, aren't they? If so, I don't think this should change.

@HeahDude yes they are. But this is quite inconsistent with {% include ... only %} and {% embed ... only %} where global variables are still available

hi all
the same with my problem ,
but this my problem ,
please help
http://stackoverflow.com/questions/41886683/how-to-add-extension-add-global-in-twig

fixed in #2933

Was this page helpful?
0 / 5 - 0 ratings