R – Extend base template in Smarty

smartytemplates

Is it possible to extend a base template with another template in Smarty?
I know this is possible in Django using the {% entend %} tag. Is there an equivalent (or workaround) in Smarty?

Thanks

Best Answer

Although this question is a bit old, I thought that maybe someone looking for this information as of august 2011 would benefit to know that this can be done now with Smarty 3.

Example With Inheritance

layout.tpl

<html>
<head>
  <title>{block name=title}Default Page Title{/block}</title>
</head>
<body>
{block name=body}{/block}
</body>
</html>

mypage.tpl

{extends file="layout.tpl"}
{block name=title}My Page Title{/block}
{block name=body}My HTML Page Body goes here{/block}

output of mypage.tpl

<html>
<head>
  <title>My Page Title</title>
</head>
<body>
My HTML Page Body goes here
</body>
</html>

Taken verbatim from: http://www.smarty.net/inheritance