@@ -1091,43 +1091,76 @@ one called ``stylesheets`` inside the ``head`` tag and another called ``javascri
10911091just above the closing ``body `` tag. These blocks will contain all of the
10921092stylesheets and JavaScripts that you'll need throughout your site:
10931093
1094- .. code -block :: html+jinja
1094+ .. configuration -block ::
10951095
1096- {# app/Resources/views/base.html.twig #}
1097- <html>
1098- <head>
1099- {# ... #}
1096+ .. code-block :: html+jinja
11001097
1101- {% block stylesheets %}
1102- <link href="{{ asset('css/main.css') }}" rel="stylesheet" />
1103- {% endblock %}
1104- </head>
1105- <body>
1106- {# ... #}
1098+ {# app/Resources/views/base.html.twig #}
1099+ <html>
1100+ <head>
1101+ {# ... #}
11071102
1108- {% block javascripts %}
1109- <script src="{{ asset('js/main.js') }}"></script>
1110- {% endblock %}
1111- </body>
1112- </html>
1103+ {% block stylesheets %}
1104+ <link href="{{ asset('css/main.css') }}" rel="stylesheet" />
1105+ {% endblock %}
1106+ </head>
1107+ <body>
1108+ {# ... #}
1109+
1110+ {% block javascripts %}
1111+ <script src="{{ asset('js/main.js') }}"></script>
1112+ {% endblock %}
1113+ </body>
1114+ </html>
1115+
1116+ .. code-block :: php
1117+
1118+ // app/Resources/views/base.html.php
1119+ <html >
1120+ <head >
1121+ <?php ... ?>
1122+
1123+ <?php $view['slots']->start('stylesheets') ?>
1124+ <link href =" <?php echo $view['assets']->getUrl('css/main.css') ?>" rel =" stylesheet" />
1125+ <?php $view['slots']->stop() ?>
1126+ </head >
1127+ <body >
1128+ <?php ... ?>
1129+
1130+ <?php $view['slots']->start('javascripts') ?>
1131+ <script src =" <?php echo $view['assets']->getUrl('js/main.js') ?>" ></script >
1132+ <?php $view['slots']->stop() ?>
1133+ </body >
1134+ </html >
11131135
11141136 That's easy enough! But what if you need to include an extra stylesheet or
11151137JavaScript from a child template? For example, suppose you have a contact
11161138page and you need to include a ``contact.css `` stylesheet *just * on that
11171139page. From inside that contact page's template, do the following:
11181140
1119- .. code-block :: html+jinja
1141+ .. configuration-block ::
1142+
1143+ .. code-block :: html+jinja
1144+
1145+ {# app/Resources/views/Contact/contact.html.twig #}
1146+ {% extends 'base.html.twig' %}
1147+
1148+ {% block stylesheets %}
1149+ {{ parent() }}
1150+
1151+ <link href="{{ asset('css/contact.css') }}" rel="stylesheet" />
1152+ {% endblock %}
11201153
1121- {# app/Resources/views/Contact/contact.html.twig #}
1122- {% extends 'base.html.twig' %}
1154+ {# ... #}
11231155
1124- {% block stylesheets %}
1125- {{ parent() }}
1156+ .. code-block :: php
11261157
1127- <link href="{{ asset('css/ contact.css') }}" rel="stylesheet" />
1128- {% endblock %}
1158+ // app/Resources/views/Contact/ contact.html.twig
1159+ <?php $view->extend('base.html.php') ?>
11291160
1130- {# ... #}
1161+ <?php $view['slots']->start('stylesheets') ?>
1162+ <link href =" <?php echo $view['assets']->getUrl('css/contact.css') ?>" rel =" stylesheet" />
1163+ <?php $view['slots']->stop() ?>
11311164
11321165 In the child template, you simply override the ``stylesheets `` block and
11331166put your new stylesheet tag inside of that block. Of course, since you want
0 commit comments