Answer the question
In order to leave comments, you need to log in
How to correctly include blocks with javascript code in two (parent-child) twigs in Symfony2?
Greetings. Need advice on the following situation:
1. There are nested templates, where the base one is:
<html lang="ru">
<head>
...
{% block stylesheets %}
<link rel="stylesheet" href="{{ asset('/css/какие-то_стили.css') }}">
{% endblock %}
</head>
<body>
<div class="container">
{% block body %}{% endblock %}
</div>
{% block javascripts %}
<script src="{{ asset( '/js/какая-то_библиотека.js' ) }}" type="text/javascript"></script>
...
{% endblock %}
</body>
</html>
{% extends 'AcmeAppBundle:Default:body.html.twig' %}
{% block items %}
...
<section class="content">
{% block list%}{% endblock %}
</section>
...
{% endblock%}
{% extends 'AcmeAppBundle:Items:items.html.twig' %}
{% block list %}
<div id="map"></div>
{% block javascripts %}
<script type="text/javascript">
var map = L.map( 'map' ).setView( [ {{ center }} ], 13 );
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a rel="nofollow" href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo( map );
{% for item in data %}
var marker = L.marker( [ {{ item.getLa }},{{ item.getLo }} ], { icon: icon } ).addTo( map );
{% endfor %}
</script>
{% endblock %}
{% endblock %}
{% block javascripts %}
<script src="{{ asset( '/js/какая-то_библиотека.js' ) }}" type="text/javascript"></script>
...
{% endblock %}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question