Tommy Meier
Tommy Meier

Reputation: 11

php smarty-like inheritance in twig template engine

The only php template engine which can handle inheritance to support e.g. a plugin-system is smarty - because it supports to load a parent template and also one or more child templates at the same time.

I couldn't find this in twig, dwoo, lette or similar template engines.

To be exact, I mean this: https://www.smarty.net/docs/en/resources.extends.tpl

+- index.tpl // the parent template
|
+--- child.tpl // a child which extends the parent
+--- child2.tpl // another child which extends the parent

Smarty will load this like so:

$smarty->display('index.tpl|child.tpl|child2.tpl');

Since I use the twig template engine in personal projects and it doesn't seems to support this feature I would appreciate any suggestions.

Sorry if I am wrong here but I don't know another place to ask.

Upvotes: 1

Views: 355

Answers (1)

delboy1978uk
delboy1978uk

Reputation: 12365

Twig can extend parent templates quite easily.

{% extends "parent.twig" %}

Check out the docs:

https://twig.symfony.com/doc/2.x/tags/extends.html

Upvotes: 1

Related Questions