Source: http://www.flyy.info/480.html
Those who have used the master pages of Asp.net should feel that this thing is worth learning from PHP.
The new smarty 3 introduces the concept of template inheritance, which can implement the same functions as the master page of Asp.net.
Template inheritance example
Layout. TPL (parent)
< Html >
< Head >
< Title > {Block name = title} default page title {/block} </ Title >
{Block name = head} {/block}
</ Head >
< Body >
{Block name = body} {/block}
</ Body >
</ Html >
Myproject. TPL (child)
{Extends file = 'layout. TPL '}
{Block name = head}
<LinkHref= "/CSS/mypage.css"REL= "Stylesheet"Type= "Text/CSS"/>
<ScriptSRC= "/JS/mypage. js"> </Script>
{/Block}
Mypage. TPL (grandchild)
{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 body goes here {/block}
To render the above use
$ Smarty->Display ('Mypage. TPL');
The resulting output is
< Html >
< Head >
< Title > My page title </ Title >
< Link Href = "/CSS/mypage.css" REL = "Stylesheet" Type = "Text/CSS" />
< Script SRC = "/JS/mypage. js" > </ Script >
</ Head >
< Body >
My HTML page body goes here
</ Body >
</ Html >