Skip to content

Commit 0ef1c68

Browse files
committed
Moved templates to app/Resources/views
1 parent 87b324a commit 0ef1c68

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

best_practices/templates.rst

+2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ In addition, Twig is the only template format with guaranteed support in Symfony
2222
3.0. As a matter of fact, PHP may be removed from the officially supported
2323
template engines.
2424

25+
.. _best_practices-template-location:
26+
2527
Template Locations
2628
------------------
2729

book/controller.rst

+15-27
Original file line numberDiff line numberDiff line change
@@ -539,57 +539,45 @@ content from the template can be used to create a ``Response`` object::
539539

540540
use Symfony\Component\HttpFoundation\Response;
541541

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));
546543

547544
return new Response($content);
548545

549546
This can even be done in just one step with the ``render()`` method, which
550547
returns a ``Response`` object containing the content from the template::
551548

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));
556550

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.
559553

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
562555

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``.
564561

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.
569564

570565
.. tip::
571566

572567
The ``renderView`` method is a shortcut to direct use of the ``templating``
573568
service. The ``templating`` service can also be used directly::
574569

575570
$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));
580572

581573
.. note::
582574

583575
It is possible to render templates in deeper subdirectories as well, however
584576
be careful to avoid the pitfall of making your directory structure unduly
585577
elaborate::
586578

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
593581

594582
.. index::
595583
single: Controller; Accessing services

0 commit comments

Comments
 (0)