how to implement (or use if it is supported) kind of late binding in TWIG.
how to transfer variable between few renders through the same instance
here is close situation with the detailed description:
Lets imagine i have global layout template, and i have kind of widgets which are called some where in the middle of the template (probably many times - lets say avatar drawing widget in the listing of users).
lets say These widgets for their functionality need to implement some javascript code in the layout:
<header>
<script type="text/javascript" src="widget_avatar.js">
</header>
so, in the twig template language i want to implement smth like:
layout.twig
<header>
{% for script_name in scripts %}
<script type="text/javascript" src="{{ script_name }}"></script>
{% endfor %}
</header>
<body>
{{ Widget('Draw_Avatar') }}
variable below set in the widget coz both widget and layout
uses the same TWIG instance:
{{ after_execution }}
</body>
draw_avatar.twig
Im widget template returning some rendered html
for my functionality i need some javascript inserted
into the "layout.twig" header
adding required javascript to the array of javascripts
{% set scripts = scripts | merge({'widget_avatar':'widget_avatar.js'}) %}
{% set after_execution = 'HELLO' %}
so, many widgets could be called, some of them may add required javascript into the array of JavaScript which should be inserted in the layout header.
twig inheritance doesn't work here coz widgets supposed to be independent and easy reusable in different templates.
BUT all templates and widgets and layouts uses the same twig instance.
I need array scripts to be used in the layout header kind of late binding.
so some block of code need to be rendered in the very end of template rendering process, how i can "say" TWIG about this ?
how i can transfer variable into the layout template from the widget after my widget is rendered ?