@@ -539,57 +539,45 @@ content from the template can be used to create a ``Response`` object::
539
539
540
540
use Symfony\Component\HttpFoundation\Response;
541
541
542
- $content = $this->renderView(
543
- 'AcmeHelloBundle:Hello:index.html.twig',
544
- array('name' => $name)
545
- );
542
+ $content = $this->renderView('Hello/index.html.twig', array('name' => $name));
546
543
547
544
return new Response($content);
548
545
549
546
This can even be done in just one step with the ``render() `` method, which
550
547
returns a ``Response `` object containing the content from the template::
551
548
552
- return $this->render(
553
- 'AcmeHelloBundle:Hello:index.html.twig',
554
- array('name' => $name)
555
- );
549
+ return $this->render('Hello/index.html.twig', array('name' => $name));
556
550
557
- In both cases, the ``Resources/views/Hello/index.html.twig `` template inside
558
- the `` AcmeHelloBundle `` will be rendered.
551
+ In both cases, the ``app/ Resources/views/Hello/index.html.twig `` template will
552
+ be rendered.
559
553
560
- The Symfony templating engine is explained in great detail in the
561
- :doc: `Templating </book/templating >` chapter.
554
+ .. sidebar :: Referencing Templates that Live inside the Bundle
562
555
563
- .. tip ::
556
+ You can also put templates in the ``Resources/views `` directory of a
557
+ bundle. You can then reference is with the
558
+ ``BundleName:DirectoryName:FileName `` syntax. E.g.
559
+ ``AppBundle:Hello:index.html.twig `` would refer to the template located in
560
+ ``src/AppBundle/Resources/views/Hello/index.html.twig ``.
564
561
565
- You can even avoid calling the ``render `` method by using the ``@Template ``
566
- annotation. See the
567
- :doc: `FrameworkExtraBundle documentation </bundles/SensioFrameworkExtraBundle/annotations/view >`
568
- more details.
562
+ The Symfony templating engine is explained in great detail in the
563
+ :doc: `Templating </book/templating >` chapter.
569
564
570
565
.. tip ::
571
566
572
567
The ``renderView `` method is a shortcut to direct use of the ``templating ``
573
568
service. The ``templating `` service can also be used directly::
574
569
575
570
$templating = $this->get('templating');
576
- $content = $templating->render(
577
- 'AcmeHelloBundle:Hello:index.html.twig',
578
- array('name' => $name)
579
- );
571
+ $content = $templating->render('Hello/index.html.twig', array('name' => $name));
580
572
581
573
.. note ::
582
574
583
575
It is possible to render templates in deeper subdirectories as well, however
584
576
be careful to avoid the pitfall of making your directory structure unduly
585
577
elaborate::
586
578
587
- $templating->render(
588
- 'AcmeHelloBundle:Hello/Greetings:index.html.twig',
589
- array('name' => $name)
590
- );
591
- // index.html.twig found in Resources/views/Hello/Greetings
592
- // is rendered.
579
+ $templating->render('Hello/Greetings/index.html.twig', array('name' => $name));
580
+ // renders app/Resources/views/Hello/Greetings/index.html.twig
593
581
594
582
.. index ::
595
583
single: Controller; Accessing services
0 commit comments