0
votes

(a) A bundle (bundle 1) holds the main parent Twig template.

(b) Another bundle (bundle 2) holds a load of controllers and those controllers each render a Twig template that's inside that bundle (bundle 2). That template also extends from the main parent one mentioned above (bundle 1). Hard coding an absolute path to the main parent template is fine.

(c) The parent template (inside bundle 1) also embeds/includes another template, which is stored in the other bundle (bundle 2).

Can I set a relative path for part (c) above so that if I created another bundle (bundle 3) it would automatically work (parent template includes templates from bundle that calls it)? It would pick up the main parent as it is an absolute path, but would it pick up part (c) above? Obviously I can't use an absolute path for the templates that the parent one is embedding/including.

1

1 Answers

0
votes

If I understand properly, you are asking how to extend templates easily while having dependencies from one bundle to another.

I'd advise you to read this documentation about overriding bundle templates.

Once read this, you will notice a link that points to the [bundle inheritance documentation].

As an example, we have 3 bundles with explicit names: - GenericSiteBundle - GenericUserBundle - SpecificSiteBundle

We want to create a generic structure for an app that could be used by other apps and we also want them to be different therefore we need to be able to change the layout (header, footer, columns, etc.).

Template structure would be something like GenericUserBundle:Security:login.html.twig extends GenericSiteBundle:Layout:simple.html.twig.

You wish to change the simple layout with a specific one; all you need to do is declare GenericSiteBundle as the parent of SpecificSiteBundle and create SpecificSiteBundle:Layout:simple.html.twig. Make sure only the bundle name is different otherwise it won't find the template in the child bundle.

Also, you will love this parent() twig function. It allows you to grab the content of the parent block and add it into the child block.

It's not exactly what you want to do but this proper way to handle inheritance.