Reputation: 751
How can I create Master Pages like in ASP.NET using PHP and Smarty?
I want to have several content place holders in the master page and simply fill them with almost big HTML chunks. So I'm looking for a better approach than what I currently have.
$content =<<< eol
<div id="home">
<img src="images/jon.jpg" id="left-image" />
</div>
eol;
$smarty->assign('content', $content);
$smarty->display('index.tpl');
Upvotes: 1
Views: 1288
Reputation: 605
U want to use template inheritance:
http://www.smarty.net/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>
Upvotes: 2
Reputation: 6992
How about creating multiple templates and usning smarty include
?
{include file="somethingelse.tpl"}
Upvotes: 2