symfony - Twig - Bubbling inline scripts from included subtemplates to javascripts block -
i'd include widget in different pages , have related scripts, defined in sub-template, happened automatically @ end of page other scripts without having several includes.
i tried use block
in included sub-template , add script in block defined in base.html.twig scripts load @ end of page.
in base.html.twig have
<html><body> <div>{% block content %}{% endblock %}</div> <aside>{% block aside %}{% endblock %}</aside> ... {% block javascripts %} <script src="..."></script> <script src="..."></script> ... {% endblock %} {% block widgetinlinescript %}{% endblock %} </body></html>
i have template profile.html.twig extends base.html.twig , looks
{% extends '::base.html.twig' %} {% block content %} ... {% endblock %} {% block aside %}{% include 'applicationrcbundle:include:promo/adspace_topright.html.twig' %}{% endblock %}
in include/widget.html.twig couldn't use {% block javascripts %}{{ parent() }} ...
because doesn't extend using parent()
fail. instead used specific block.
{% block widgetinlinescript %} <script type="text/javascript" id="widgetinlinescript" > ... </script> {% endblock %}
twig compile template render script in dom after widget instead of rendering in place of {% block widgetinlinescript %}
@ end of page.
so possible use block
inside included subtemplate ? thanks
i answered similar question today:
append content block multiple subtemplates
basically created blocks using "horizontal reuse" technique:
{% use "blocks.html" sidebar base_sidebar %}
you can check doc here:
Comments
Post a Comment