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!
Written by Matteo Giordano
Related protips
1 Response
This is a great one, thanks!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#