@@ -1059,43 +1059,76 @@ one called ``stylesheets`` inside the ``head`` tag and another called ``javascri
1059
1059
just above the closing ``body `` tag. These blocks will contain all of the
1060
1060
stylesheets and JavaScripts that you'll need throughout your site:
1061
1061
1062
- .. code -block :: html+jinja
1062
+ .. configuration -block ::
1063
1063
1064
- {# app/Resources/views/base.html.twig #}
1065
- <html>
1066
- <head>
1067
- {# ... #}
1064
+ .. code-block :: html+jinja
1068
1065
1069
- {% block stylesheets %}
1070
- <link href="{{ asset('css/main.css') }}" rel="stylesheet" />
1071
- {% endblock %}
1072
- </head>
1073
- <body>
1074
- {# ... #}
1066
+ {# app/Resources/views/base.html.twig #}
1067
+ <html>
1068
+ <head>
1069
+ {# ... #}
1075
1070
1076
- {% block javascripts %}
1077
- <script src="{{ asset('js/main.js') }}"></script>
1078
- {% endblock %}
1079
- </body>
1080
- </html>
1071
+ {% block stylesheets %}
1072
+ <link href="{{ asset('css/main.css') }}" rel="stylesheet" />
1073
+ {% endblock %}
1074
+ </head>
1075
+ <body>
1076
+ {# ... #}
1077
+
1078
+ {% block javascripts %}
1079
+ <script src="{{ asset('js/main.js') }}"></script>
1080
+ {% endblock %}
1081
+ </body>
1082
+ </html>
1083
+
1084
+ .. code-block :: php
1085
+
1086
+ // app/Resources/views/base.html.php
1087
+ <html >
1088
+ <head >
1089
+ <?php ... ?>
1090
+
1091
+ <?php $view['slots']->start('stylesheets') ?>
1092
+ <link href =" <?php echo $view['assets']->getUrl('css/main.css') ?>" rel =" stylesheet" />
1093
+ <?php $view['slots']->stop() ?>
1094
+ </head >
1095
+ <body >
1096
+ <?php ... ?>
1097
+
1098
+ <?php $view['slots']->start('javascripts') ?>
1099
+ <script src =" <?php echo $view['assets']->getUrl('js/main.js') ?>" ></script >
1100
+ <?php $view['slots']->stop() ?>
1101
+ </body >
1102
+ </html >
1081
1103
1082
1104
That's easy enough! But what if you need to include an extra stylesheet or
1083
1105
JavaScript from a child template? For example, suppose you have a contact
1084
1106
page and you need to include a ``contact.css `` stylesheet *just * on that
1085
1107
page. From inside that contact page's template, do the following:
1086
1108
1087
- .. code-block :: html+jinja
1109
+ .. configuration-block ::
1110
+
1111
+ .. code-block :: html+jinja
1112
+
1113
+ {# app/Resources/views/Contact/contact.html.twig #}
1114
+ {% extends 'base.html.twig' %}
1115
+
1116
+ {% block stylesheets %}
1117
+ {{ parent() }}
1118
+
1119
+ <link href="{{ asset('css/contact.css') }}" rel="stylesheet" />
1120
+ {% endblock %}
1088
1121
1089
- {# app/Resources/views/Contact/contact.html.twig #}
1090
- {% extends 'base.html.twig' %}
1122
+ {# ... #}
1091
1123
1092
- {% block stylesheets %}
1093
- {{ parent() }}
1124
+ .. code-block :: php
1094
1125
1095
- <link href="{{ asset('css/ contact.css') }}" rel="stylesheet" />
1096
- {% endblock %}
1126
+ // app/Resources/views/Contact/ contact.html.twig
1127
+ <?php $view->extend('base.html.php') ?>
1097
1128
1098
- {# ... #}
1129
+ <?php $view['slots']->start('stylesheets') ?>
1130
+ <link href =" <?php echo $view['assets']->getUrl('css/contact.css') ?>" rel =" stylesheet" />
1131
+ <?php $view['slots']->stop() ?>
1099
1132
1100
1133
In the child template, you simply override the ``stylesheets `` block and
1101
1134
put your new stylesheet tag inside of that block. Of course, since you want
0 commit comments