I need include a twig file with a block, but this file will be added in differents places. The file is this:
HTML CODE BLABLA
{% block javascript %}
<script>
Code associated with the html
</script>
{% endblock %}
With include, is inserted all but not respect order block. Also I can load template with "use" but I havent access to the vars :S
{% include 'file.html.twig' %} No respect block
{% use 'file.html.twig' %} cant access vars
How can I do it ?. (Sorry for my english)
To override a block you have to use the extends
function. Your template may extends the parent, so the javascript
block from the sub-template will replace the one from the parent.
You cannot mix include
and extend
.
Have you tried the embed tag?
The embed tag combines the behaviour of include and extends. It allows you to include another template's contents, just like include does. But it also allows you to override any block defined inside the included template, like when extending a template.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With