3
votes

I'm learning symfony2 and like it very much (migrating from ZendFramework 1.x) but I'm stuck now with twig templating. Can you point me to the right direction?

My application has many customers and each has some customization (mostly templates, but also controllers, etc.).

I try to achieve this by bundle inheritance / I created ClientBundle which inherits from BaseBundle holding all basic code and templates... it works as I need for everything bud templates. When I create template in ClientBundle it overlays the template from BaseBundle and I cannot get access from the ClientBundle template to the original template from BaseBundle. I would like to extend the parent template, not overlay it... is this impossible?

Thank you!

2

2 Answers

4
votes

Using the standard Symfony extends notation to reference a parent's bundle template results in fatal error. Symfony interprets your template reference to BaseBundle as ChildBundle as a result of bundle inheritance causing a function nesting level exception.

You can reference the parent's bundle template file directly using the following notation:

{% extends "@Client/Foo/bar.html.twig" %}

in replacement for:

{% extends "ClientBundle:Foo:bar.html.twig" %}

Twig's FilesystemLoader splits the reference string into namespace (Client) and path (Foo/bar.html.twig). Namespace is your bundle name without the Bundle suffix. Full path for each namespace is resolved by concatenating default <bundle_path>/Resources/views/ with supplied path.

1
votes

The standard command in twig template for extention is:

{% extends 'BaseBundle::yourTemplate.html.twig' %}

You probably use the same name for template in your child bundle (you probably have a yourTemplate.html.twig in both your parent and your child bundle so the child template overrides the parent). In this case, you can rename your child template (yourTemplate2.html.twig) and then extend the child template from parent. More about bundles inheritance and twig templates extentions: http://symfony.com/doc/current/cookbook/bundles/inheritance.html http://symfony.com/doc/current/book/templating.html