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