一、php代码
<?php
//Composer引入Smarty模板引擎
require __DIR__ . '/config/config.php';
//渲染demo.html页面
$smarty->display('demo.html');
二、demo.html前端页面
{* 引入模板文件 *}
{extends file="layout.html"}
{* 头部 *}
{block name="header"}
{$smarty.block.parent}
<h1 style="color:red">,我是头部</h1>
{/block}
{* 主体 *}
{block name="content"}
{$smarty.block.parent}
<h1 style="color:red">,我是主体</h1>
{/block}
{* 尾部 *}
{block name="footer"}
{$smarty.block.parent}
<h1 style="color:red">,我是尾部</h1>
{/block}
三、.layout.html模板页面
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{block name="title"}模板继承案例{/block}</title>
</head>
<body>
{block name="header"}
1.你好
{/block}
{block name="content"}
2.你好
{/block}
{block name="footer"}
3.你好
{/block}
</body>
</html>
四、运行效果