0
votes

I have a question regarding adding javascript to child elements. How do you do that?

I have this setup:

base.html.twig:

{% block content %}
{% endblock content %}

{% block script %}
{% endblock script %}

index.html.twig:

{% extends base.html.twig %}

{% include intro.html.twig %}

{% block content %} 
<html></html>
{% endblock content %}

{% block script %}
<script></script>
{% endblock script %}

intro.html.twig:

{% block script %}
<script></script>
{% endblock script %}

I want to add more javascript files into the intro.html.twig file, but it doesn't append it to the script block in index.html.twig.

All help appreciated!

UPDATE I want to send some parameters with intro.html.twig:

{% extends 'intro.html.twig' with {
'title': 'title',
'type': 'test',
} %}

is this possible using extends, or can I only use with with include?

1
why don't you define your parameters in controller, then you can access it from parent and child template.Arcv

1 Answers

1
votes

index.html.twig

{% extends intro.html.twig %}

{% block content %} 
    <html></html>
{% endblock content %}

{% block script %}
    {{ parent() }}
    <script></script>
{% endblock script %}

intro.html.twig

{% extends base.html.twig %}

{% block script %}
    <script></script>
{% endblock script %}