Donnie Donnie - 4 months ago 18
YAML Question

Symfony3: Passing variables to FrameworkBundle:Template:template

Just want to double check with the community, there are no chance to pass variables to a template rendered through FrameworkBundle:Template:template in the routing file right?

Thank you

Answer

It is by design:

But if you're rendering a simple template that doesn't need any data passed into it, you can avoid creating the controller entirely, by using the built-in FrameworkBundle:Template:template controller. https://symfony.com/doc/current/templating/render_without_controller.html

You can see that you can only pass three cache headers options and template name to render:

public function templateAction($template, $maxAge = null, $sharedAge = null, $private = null)
{
    ...
}

https://github.com/symfony/framework-bundle/blob/master/Controller/TemplateController.php#L37

So the anwser is: There is no chance to pass custom variables (excluding http cache headers options) to a template rendered through FrameworkBundle:Template:template.

Comments