Smarty母版页

时间:2010-10-05 23:15:31

标签: php smarty

如何使用PHP和Smarty在ASP.NET中创建母版页?

我希望在母版页中有几个内容占位符,只需用几乎大的HTML块填充它们。所以我正在寻找比现在更好的方法。

$content =<<< eol
    <div id="home">
        <img src="images/jon.jpg" id="left-image" />
    </div>
eol;

$smarty->assign('content', $content);
$smarty->display('index.tpl');

2 个答案:

答案 0 :(得分:2)

如何创建多个模板并使用smarty include

{include file="somethingelse.tpl"}

答案 1 :(得分:2)

你想使用模板继承:

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}

输出mypage.tpl

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