Template inheritance is more convenient than using the Include method, which is to facilitate the introduction of different CSS JS files on each page;
LAYOUT.TPL (parent template)
MYPROJECT.TPL (sub-template)
{extends file= ' layout.tpl '} {Block Name=head} <link href= "/css/mypage.css" rel= "stylesheet" type= "Text/css"/> <script src= "/js/mypage.js "></script>{/block}
Mypage.tpl (grandson Template)
{extends file= ' myproject.tpl '} {Block Name=title} my page title {/block}{block Name=head} <link href= "/css/mypage.css" rel= "stylesheet" type= "Text/css"/ > <script src= "/js/mypage.js" ></script>{/block}{block name=body} My HTML page content is here {/block}
Show the above template:
$smarty->display (' Mypage.tpl ');
Alternatively, instead of using {extends} inheritance in a template, you can inherit by defining an inheritance tree within PHP, using the extends: resource type.
The following code returns the same result as the example above:
<?php$smarty->display (' Extends:layout.tpl|myproject.tpl|mypage.tpl ');?>
Smarty Template Inheritance