Search code examples
templatessymfonytwigpartials

Template Partials in Symfony 2


Are there such things as partials in Symfony 2, reusable templates from anywhere, effectively?

I have found include http://twig.sensiolabs.org/doc/tags/include.html but this only allows the rendering of a template in a specific directory structure.

What I really want a folder that contains all my partial templates, rather than lumping them into my main views?

So I want to be able to do something like

{% include "Bundle:Default:Partials:view.html.twig" %}

Update

I do not want to use the enforced structure of Bundle:Controller:Template structure. I do not want to use this as it means putting all my template partials in with my main view templates. I need something that lets me do Bundle:Controller:PartialDir:Template


Solution

  • You can already do that. The symfony2 docs has a section describing how to do this.

    http://symfony.com/doc/current/book/templating.html#including-other-templates