pj1opa
Last Updated: February 25, 2016
·
4.816K
· malteo
D19108207d7ebfd0e18e4a7108c5d656

How to render a template for a static page without a custom controller in Symfony2

It's usual to have a static page even in a complex web application, like an "About" or "Contact us" section of a frontend site.

In Symfony, you'll usually want to fill a block of an outer base or layout Twig view with a static content.

It's possible to do so without writing a dedicated controller by handling the request to the built-in TemplateController with this route:

about:
pattern: /about/
defaults:
    _controller: FrameworkBundle:Template:template
    template: AcmeWebsiteBundle:Frontend:about.html.twig

Just add it to your routing.yml and place the .html.twig file under the correct path. That's it!

Say Thanks
Respond

1 Response
Add your response

1332
10dfb9071cea4272eabdfb91d18f377f

This is a great one, thanks!

over 1 year ago ·