Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Location of template rendering in Symfony2

Tags:

php

symfony

Where in Symfony2 is template rendering launched?

I am asking for the most general class/method handling the template logic, I guess by launching the configured template engine, like Twig for example.

Or to put the question even more concretely ... a controller delegates the layout to a specific template, like example.html.twig ... where is this filename used and passed for the first time?

like image 324
Raffael Avatar asked Jul 13 '11 13:07

Raffael


People also ask

What is raw in twig?

raw. By default, everything in Twig gets escaped when automatic escaping is enabled. If you don't want to escape a variable you'll have to explicitly mark it as safe which you can do by using the raw filter. This only works if the raw filter is the last filter that is applied to the filter.

What is block in twig?

Blocks are used for inheritance and act as placeholders and replacements at the same time. They are documented in detail in the documentation for the extends tag. Block names must consist of alphanumeric characters, and underscores. The first char can't be a digit and dashes are not permitted.

What is Page HTML twig?

html. twig - the body of Developer Portal HTML page. node. html. twig - the template for all of the content nodes.


1 Answers

In the most general case, assuming you're using the FrameworkBundle (if you're using Standard Edition, you are), the render function just calls $this->container->get('templating')->renderResponse, just passing along the parameters.

Engines (like the twig engine) implement Symfony\Component\Templating\EngineInterface.

You can check out vendor/symfony/src/Symfony/Bundle/FrameworkBundle/Controller/Controller.php (and the other relevant files, like the ones in the TwigBundle), if you'd like to take a close look at how it works.

like image 59
jdd Avatar answered Sep 28 '22 23:09

jdd