@@ -24,15 +24,15 @@ your application configuration file:
2424
2525 .. code-block :: yaml
2626
27- # app/ config/config.yml
27+ # config/packages/framework.yaml
2828 framework :
2929 # ...
3030 templating :
3131 engines : ['twig', 'php']
3232
3333 .. code-block :: xml
3434
35- <!-- app/ config/config .xml -->
35+ <!-- config/packages/framework .xml -->
3636 <?xml version =" 1.0" encoding =" UTF-8" ?>
3737 <container xmlns =" http://symfony.com/schema/dic/services"
3838 xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
@@ -53,6 +53,7 @@ your application configuration file:
5353
5454 .. code-block :: php
5555
56+ // config/packages/framework.php
5657 $container->loadFromExtension('framework', array(
5758 // ...
5859 'templating' => array(
@@ -67,28 +68,11 @@ below renders the ``index.html.php`` template::
6768 // src/Controller/HelloController.php
6869
6970 // ...
70- public function indexAction ($name)
71+ public function index ($name)
7172 {
72- return $this->render(
73- 'AppBundle:Hello:index.html.php',
74- array('name' => $name)
75- );
76- }
77-
78- You can also use the `@Template `_ shortcut to render the default
79- ``AppBundle:Hello:index.html.php `` template::
80-
81- // src/Controller/HelloController.php
82- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
83-
84- // ...
85-
86- /**
87- * @Template(engine="php")
88- */
89- public function indexAction($name)
90- {
91- return array('name' => $name);
73+ return $this->render('hello/index.html.php', array(
74+ 'name' => $name
75+ ));
9276 }
9377
9478.. caution ::
@@ -98,24 +82,24 @@ You can also use the `@Template`_ shortcut to render the default
9882 the ``@ `` notation for Twig namespaces will no longer be supported for the
9983 ``render() `` method::
10084
101- public function indexAction ()
85+ public function index ()
10286 {
10387 // ...
10488
10589 // namespaced templates will no longer work in controllers
106- $this->render('@App/Default /index.html.twig');
90+ $this->render('@SomeNamespace/hello /index.html.twig');
10791
10892 // you must use the traditional template notation
109- $this->render('AppBundle:Default: index.html.twig');
93+ $this->render('hello/ index.html.twig');
11094 }
11195
11296 .. code-block :: twig
11397
11498 {# inside a Twig template, namespaced templates work as expected #}
115- {{ include('@App/Default /index.html.twig') }}
99+ {{ include('@SomeNamespace/hello /index.html.twig') }}
116100
117101 {# traditional template notation will also work #}
118- {{ include('AppBundle:Default: index.html.twig') }}
102+ {{ include('hello/ index.html.twig') }}
119103
120104
121105 .. index ::
@@ -135,31 +119,24 @@ the ``extend()`` call:
135119.. code-block :: html+php
136120
137121 <!-- templates/Hello/index.html.php -->
138- <?php $view->extend('AppBundle:: layout.html.php') ?>
122+ <?php $view->extend('layout.html.php') ?>
139123
140124 Hello <?php echo $name ?>!
141125
142- The ``AppBundle::layout.html.php `` notation sounds familiar, doesn't it? It
143- is the same notation used to reference a template. The ``:: `` part simply
144- means that the controller element is empty, so the corresponding file is
145- directly stored under ``views/ ``.
146-
147126Now, have a look at the ``layout.html.php `` file:
148127
149128.. code-block :: html+php
150129
151130 <!-- templates/layout.html.php -->
152- <?php $view->extend(':: base.html.php') ?>
131+ <?php $view->extend('base.html.php') ?>
153132
154133 <h1>Hello Application</h1>
155134
156135 <?php $view['slots']->output('_content') ?>
157136
158- The layout is itself decorated by another one (``:: base.html.php ``). Symfony
137+ The layout is itself decorated by another one (``base.html.php ``). Symfony
159138supports multiple decoration levels: a layout can itself be decorated by
160- another one. When the bundle part of the template name is empty, views are
161- looked for in the ``templates/ `` directory. This directory stores
162- global views for your entire project:
139+ another one:
163140
164141.. code-block :: html+php
165142
@@ -196,8 +173,8 @@ decorating the template. In the ``index.html.php`` template, define a
196173
197174.. code-block :: html+php
198175
199- <!-- templates/Hello /index.html.php -->
200- <?php $view->extend('AppBundle:: layout.html.php') ?>
176+ <!-- templates/hello /index.html.php -->
177+ <?php $view->extend('layout.html.php') ?>
201178
202179 <?php $view['slots']->set('title', 'Hello World Application') ?>
203180
@@ -238,17 +215,17 @@ Create a ``hello.html.php`` template:
238215
239216.. code-block :: html+php
240217
241- <!-- templates/Hello /hello.html.php -->
218+ <!-- templates/hello /hello.html.php -->
242219 Hello <?php echo $name ?>!
243220
244221And change the ``index.html.php `` template to include it:
245222
246223.. code-block :: html+php
247224
248- <!-- templates/Hello /index.html.php -->
249- <?php $view->extend('AppBundle:: layout.html.php') ?>
225+ <!-- templates/hello /index.html.php -->
226+ <?php $view->extend('layout.html.php') ?>
250227
251- <?php echo $view->render('AppBundle :Hello: hello.html.php', array('name' => $name)) ?>
228+ <?php echo $view->render('hello/ hello.html.php', array('name' => $name)) ?>
252229
253230The ``render() `` method evaluates and returns the content of another template
254231(this is the exact same method as the one used in the controller).
@@ -270,33 +247,15 @@ If you create a ``fancy`` action, and want to include it into the
270247
271248 <!-- templates/Hello/index.html.php -->
272249 <?php echo $view['actions']->render(
273- new \S ymfony\C omponent\H ttpKernel\C ontroller\C ontrollerReference('AppBundle:Hello: fancy', array(
274- 'name' => $name,
275- 'color' => 'green',
276- ))
250+ new \S ymfony\C omponent\H ttpKernel\C ontroller\C ontrollerReference(
251+ 'App\C ontroller\H elloController::fancy',
252+ array(
253+ 'name' => $name,
254+ 'color' => 'green',
255+ )
256+ )
277257 ) ?>
278258
279- Here, the ``AppBundle:Hello:fancy `` string refers to the ``fancy `` action of the
280- ``Hello `` controller::
281-
282- // src/Controller/HelloController.php
283-
284- class HelloController extends Controller
285- {
286- public function fancyAction($name, $color)
287- {
288- // create some object, based on the $color variable
289- $object = ...;
290-
291- return $this->render('AppBundle:Hello:fancy.html.php', array(
292- 'name' => $name,
293- 'object' => $object
294- ));
295- }
296-
297- // ...
298- }
299-
300259But where is the ``$view['actions'] `` array element defined? Like
301260``$view['slots'] ``, it's called a template helper, and the next section tells
302261you more about those.
@@ -332,10 +291,10 @@ pattern:
332291
333292.. code-block :: yaml
334293
335- # src/Resources/ config/routing.yml
336- hello : # The route name
337- path : /hello/{name}
338- defaults : { _controller: AppBundle:Hello: index }
294+ # config/routes.yaml
295+ hello :
296+ path : /hello/{name}
297+ controller : App\Controller\HelloController:: index
339298
340299 Using Assets: Images, JavaScripts and Stylesheets
341300~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0 commit comments