21.10.2015 Views

1-33

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Symfony2 – Franz Jordán 2011<br />

<br />

PDF Version<br />

<br />

Final Thoughts<br />

The templating engine in Symfony is a powerful tool that can be used each time you need to<br />

generate presentational content in HTML, XML or any other format. And though templates are a<br />

common way to generate content in a controller, their use is not mandatory.<br />

The Response object returned by a controller can be created with our without the use of a<br />

template:<br />

// creates a Response object whose content is the rendered template<br />

$response = $this->render('AcmeArticleBundle:Article:index.html.twig');<br />

// creates a Response object whose content is simple text<br />

$response = new Response('response content');<br />

Symfony's templating engine is very flexible and two different template renderers are available<br />

by default: the traditional PHP templates and the sleek and powerful Twig templates. Both<br />

support a template hierarchy and come packaged with a rich set of helper functions capable of<br />

performing the most common tasks.<br />

Overall, the topic of templating should be thought of as a powerful tool that's at your disposal.<br />

In some cases, you may not need to render a template, and in Symfony2, that's absolutely fine.<br />

Learn more from the Cookbook<br />

How to use PHP instead of Twig for Templates<br />

How to customize Error Pages<br />

82

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!