smarty静态模版页面的引入,{include file="路径+文件"}路径计算是以当前的模板文件计算的


首先在/smarty/template/下建立header.html.footer.html文件代码如下

header.html

<!DOCTYPE html>
<html>
<head>
	<title>网站头部</title>
	<meta charset="utf-8">
	<meta name="keywords" content="">
	<script type="text/javascript" src="./public/Js/xxx.js"></script>
	<link type="text/css" rel="stylesheet" href="./public/Css/common.css" />

</head>
<body>
	<div class="head">这是网站头部</div>
</body>
</html>

footer.html


<!DOCTYPE html>
<html>
<head>
	<title>网站底部</title>
	<meta charset="utf-8">
	<meta name="keywords" content="">
	<script type="text/javascript" src="./public/Js/xxx.js"></script>
	<link type="text/css" rel="stylesheet" href="./public/Css/common.css" />

</head>
<body>
	<div class="foot">这是网站底部</div>
</body>
</html>

其次,在/smarty/public下建立Js,Css,Image三个文件存放文件,Css/common.css

smarty模板引擎总结五include引入模板_smarty


index.html

<!DOCTYPE html>
<html>
<head>
	<title>模板首页</title>
	<meta charset="utf-8">
	<meta name="keywords" content="">
	<script type="text/javascript" src="./public/Js/xxx.js"></script>
	<link type="text/css" rel="stylesheet" href="./public/Css/common.css" />

</head>
<body>
	<!--include引入模版页面的路径注意,header.html,footer.html,和index.html同级,不用./template/header.html-->
	{include file="header.html"}
	<div class="body">
		<h1>这是网站主体部分</h1>
	</div>
	{include file="footer.html"}
</body>
</html>


index.php

<?php
	require("./Smarty.inc.php");//引入smarty的初始化文件
	
	
	$smarty->display("index.html"); //这行代码要放到最后否则会报错

?>

在IE里打开index.php的效果

smarty模板引擎总结五include引入模板_include_02