@@ -1091,43 +1091,76 @@ one called ``stylesheets`` inside the ``head`` tag and another called ``javascri
1091
1091
just above the closing ``body `` tag. These blocks will contain all of the
1092
1092
stylesheets and JavaScripts that you'll need throughout your site:
1093
1093
1094
- .. code -block :: html+jinja
1094
+ .. configuration -block ::
1095
1095
1096
- {# app/Resources/views/base.html.twig #}
1097
- <html>
1098
- <head>
1099
- {# ... #}
1096
+ .. code-block :: html+jinja
1100
1097
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
+ {# ... #}
1107
1102
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 >
1113
1135
1114
1136
That's easy enough! But what if you need to include an extra stylesheet or
1115
1137
JavaScript from a child template? For example, suppose you have a contact
1116
1138
page and you need to include a ``contact.css `` stylesheet *just * on that
1117
1139
page. From inside that contact page's template, do the following:
1118
1140
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 %}
1120
1153
1121
- {# app/Resources/views/Contact/contact.html.twig #}
1122
- {% extends 'base.html.twig' %}
1154
+ {# ... #}
1123
1155
1124
- {% block stylesheets %}
1125
- {{ parent() }}
1156
+ .. code-block :: php
1126
1157
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') ?>
1129
1160
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() ?>
1131
1164
1132
1165
In the child template, you simply override the ``stylesheets `` block and
1133
1166
put your new stylesheet tag inside of that block. Of course, since you want
0 commit comments