Inheritance <{extends}>
- {extends} tags are used in the first line of the template;
- If the child template inherits the parent template with the {extends} tag, it can only contain the {block} tag (content), and any other template content will be ignored;
Backstage (zi.php)
<? PHP include (".. /init.inc.php "); include (".. /dbda.php "); $db New Dbda (); $smarty->assign ("Shouye", "Home"); $smarty->assign ("Chanpin", "Product"); $smarty->display ("zi.html");
Parent template (fu.html):
<!DOCTYPE HTML Public "-//W3C//DTD XHTML 1.0 transitional//en" "http://www.w3.org/TR/xhtml1/DTD/ Xhtml1-transitional.dtd "><HTMLxmlns= "http://www.w3.org/1999/xhtml"><Head><Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8" /><title><{blockname= ' Biaoti '}>Parent Template<{/block}></title>//Head<{blockname= ' head '}><{/block}><styletype= "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><DivID= "Daohang"><Divclass= ' Menu '><{$shouye}></Div><Divclass= ' Menu '><{$chanpin}></Div></Div>Main body:<Divstyle= "width:300px; height:200px"><{blockname= ' Neirong '}><{/block}></Div>Tail:<Divstyle= "width:100%; height:100px; Background-color: #CCC"><{blockname= ' di '}><{/block}></Div><DivID= "Footer"></Div></Body></HTML>
Child Template (zi.html):
<{extendsfile= ' fu.html '}>//Call function, the child template inherits everything from the parent template, the child has rewritten the parent, modified or appended with block tags, the order doesn't matter, and you want to change where to add the block tag<{blockname= ' Biaoti '}>//Modify Title sub-page<{/block}>Modify Style://To modify the style to have two parts<{blockname= ' head '}><styletype= "Text/css">#nr{width:200px;Height:200px;Background-color:#03F}</style><{/block}>//Style sheet Section<{blockname= ' Neirong '}> <DivID= "NR"></Div><{/block}>//Modified Content Section<{blockname= ' di '}>the bottom of the page<{/block}>
Smarty Function-Inherit extents