aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/smarty/smarty/docs/programmers/resources/resources-extends.md
blob: ad2e8f5d84124a96ff3bc1db958cb02d815f46b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
Extends Template Resources {#resources.extends}
==========================

The `extends:` resource is used to define child/parent relationships for
template inheritance from the PHP script. For details see section of
[Template Interitance](#advanced.features.template.inheritance).

As of Smarty 3.1 the `extends:` resource may use any available [template
resource](#resources), including `string:` and `eval:`. When [templates
from strings](#resources.string) are used, make sure they are properly
(url or base64) encoded. Is an `eval:` resource found within an
inheritance chain, its \"don\'t save a compile file\" property is
superseeded by the `extends:` resource. The templates within an
inheritance chain are not compiled separately, though. Only a single
compiled template will be generated.

> **Note**
>
> Use this when inheritance is required programatically. When inheriting
> within PHP, it is not obvious from the child template what inheritance
> took place. If you have a choice, it is normally more flexible and
> intuitive to handle inheritance chains from within the templates.


    <?php
    $smarty->display('extends:parent.tpl|child.tpl|grandchild.tpl'); 

    // inheritance from multiple template sources
    $smarty->display('extends:db:parent.tpl|file:child.tpl|grandchild.tpl|eval:{block name="fooBazVar_"}hello world{/block}'); 
    ?>

      

See also [Template Inheritance](#advanced.features.template.inheritance)
[`{block}`](#language.function.block) and
[`{extends}`](#language.function.extends).