标签:
继承<{extends}>
后台(zi.php)
<?php include("../init.inc.php"); include("../DBDA.php"); $db = new DBDA(); $smarty->assign("shouye","首页"); $smarty->assign("chanpin","产品"); $smarty->display("zi.html");
父级模板(fu.html):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><{block name=‘biaoti‘}>父模板<{/block}></title> //头 <{block name=‘head‘}> <{/block}> <style type="text/css"> #daohang{ width:100%; height:50px} .menu{ width:100px; height:50px; background-color:#66C; float:left; text-align:center; line-height:50px; vertical-align:middle} #footer{ width:100%; height:100px; background-color:#F36 } </style> </head> <body> <div id="daohang"> <div class=‘menu‘><{$shouye}></div> <div class=‘menu‘><{$chanpin}></div> </div> 主体: <div style="width:300px; height:200px"> <{block name=‘neirong‘}> <{/block}> </div> 尾: <div style="width:100%; height:100px; background-color:#CCC"> <{block name=‘di‘}> <{/block}> </div> <div id="footer"></div> </body> </html>
子级模板(zi.html):
<{extends file=‘fu.html‘}> //调用函数,子模板继承父模板的一切,子对父进行了重写,用block块标签进行修改或追加,顺序无所谓,想修改哪就在哪加block标签 <{block name=‘biaoti‘}>//修改标题 子页面 <{/block}> 修改样式: //要修改样式得有两部分 <{block name=‘head‘}> <style type="text/css"> #nr{width:200px; height:200px; background-color:#03F} </style> <{/block}> //样式表部分 <{block name=‘neirong‘}> <div id="nr"></div> <{/block}> //修改的内容部分 <{block name=‘di‘}> 网页的底部 <{/block}>
标签:
原文地址:http://www.cnblogs.com/jinshui/p/5701117.html