Twig: Multiple inheritance

Created on 28 Nov 2017  Â·  2Comments  Â·  Source: twigphp/Twig

The docs say quite specifically that Twig doesn't support multiple inheritance - more than one extends per render, yet it seems to support exactly that, both in 1.x and 2.x.

The Symfony docs even recommend this approach as the "common way" to manage structuring templates.

Is the Twig documentation out of date or am I missing something here?

Most helpful comment

Looks like you are misunderstanding the term of multiple inheritance.

In some programming languages you can have something like this (this code will not work with PHP):

class ClassA {}
class ClassB {}
class ClassC extends ClassA, ClassB {} #ClassC extends two classes

So the hierarchy is as follows (arrows show direction from base class to child):

ClassA ↘
         ClassC
ClassB ↗

But in linked Symfony docs you will get the following hierarchy:

base.html.twig -> blog/layout.html.twig -> blog/index.html.twig

This is simple chained hierarchy, without multiple inheritance.

All 2 comments

Looks like you are misunderstanding the term of multiple inheritance.

In some programming languages you can have something like this (this code will not work with PHP):

class ClassA {}
class ClassB {}
class ClassC extends ClassA, ClassB {} #ClassC extends two classes

So the hierarchy is as follows (arrows show direction from base class to child):

ClassA ↘
         ClassC
ClassB ↗

But in linked Symfony docs you will get the following hierarchy:

base.html.twig -> blog/layout.html.twig -> blog/index.html.twig

This is simple chained hierarchy, without multiple inheritance.

Read things twice, Dan, always read things twice.

Thanks for the explanation, much appreciated.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scila1996 picture scila1996  Â·  3Comments

xxfaxy picture xxfaxy  Â·  6Comments

garak picture garak  Â·  5Comments

mnapoli picture mnapoli  Â·  5Comments

SDPrio picture SDPrio  Â·  3Comments