PHP smarty函数

模板继承

fuji.html

<title><{block name='biaoti'}><{/block}></title>
 <{block name='head'}><{/block}>
 <style type="text/css">
 .menu
 {
     width:100%;
     height:80px;
     background-color:#06F;     
 }
 .menus
 {
     float:left;
     width:100px;
     height:80px;
     line-height:80px;
     vertical-align:middle;
     text-align:center;
     margin-left:80px;
     color:#FFF; 
 }
 .dibu
 { 
     width:100%;
     height:100px;
     background-color:#06F;
     line-height:100px;
     vertical-align:middle;
     text-align:center;
     color:#FFF; 
 } 
 </style>
 
</head>

<body>
<div class="menu">
    <div class="menus">主页</div>
    <div class="menus"><{$jianjie}></div>
    <div class="menus"><{$xinwen}></div>
    <div style="clear:both"></div>
</div>
<div style="100%;">
    <{block name='neirong'}><{/block}>
</div>
<div class="dibu">
      底部信息  
</div>
</body>

zi.html

<{extends file='fuji.html'}>
<{block name='biaoti'}>
    子模板  
<{/block}>
<{block name='head'}>
  <style type="text/css">
      .neirong
    {
        width:100%;
        height:350px;
        color:#666;
    }
  </style>
<{/block}>
<{block name='neirong'}>
  <div class="neirong">
      <br>这是子模板
  </div>  
<{/block}>

zi.php

<?php
include("../init.inc.php");
include("../../dbda.php");
$db=new DBDA();

$smarty->assign("jianjie","简介");
$smarty->assign("xinwen","新闻");

$smarty->display("zi.html");

原文地址:https://www.cnblogs.com/yy01/p/5701022.html