Aloha,
I have created a pull request to remove the magic behavior for template lookup
based on the _format:
https://github.com/fabpot/symfony/pull/390
Right now the format for a template is essentially
[bundle]:[controller]:[name].[format].[renderer]
For example:
$this->render('FooBundle:Default:index.json.twig');
Will look for FooBundle/Resources/views/Default/index.json.twig by default.
HTML is sort of implicit:
$this->render('FooBundle:Default:index.html.twig');
Will look for FooBundle/Resources/views/Default/index.twig by default.
If you omit [format] there is a bit of magic happening
$this->render('FooBundle:Default:index.twig);
Wil add the _format you matched in your route into the template name. So if you
matched _format to html (which is the default) then the above will look for
index.twig for html which is FooBundle/Resources/views/Default/index.twig. But
if the _format is json it would look for FooBundle:Default:index.json.twig.
This helps in making it a bit easier to handle different output formats with
one controller. But I am not aware of a single person who wasn't confused for
quite a bit when they first encountered this.
Also lets imagine you want to embed some html into a json reponse, you need to
make sure you explicitly set html when rendering the html.
So imagine _format is set to json, one would have to use index.html.twig to
find index.twig and index.twig to find index.json.twig:
$html = $this->templating->render('FooBundle:Default:index.html.twig',
$parameters); // looks for index.twig
$this->render('FooBundle:Default:index.twig', array('html' => $html)); // looks
for index.json.twig
Again the above pull removes this behavior entirely. Basically it would go back
to doing more or less a 1:1 mapping, what you ask for is then what you get. Now
you might still want to have some automatic template switching based on the
format. Then just do:
$this->render('FooBundle:Default:index.'.$this->request->getRequestFormat().'.twig);
regards,
Lukas Kahwe Smith
[email protected]
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en