Last Updated: September 09, 2019
·
6.604K
· malteo

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!

1 Response
Add your response

This is a great one, thanks!

over 1 year ago ·