Template Inheritance (Content page Inherits master page): Implements code reuse.
Resolving code reuse issues:
Scenario 1: Use include all (include the equivalent of copy and paste, which will form a large number of the same page, occupy bandwidth)
Scenario 2: Full use of extends (recommended use of the scheme)
Scenario 3: One using include, one using extends (not recommended)
Steps:
The first step is to create a parent template for the child template to inherit, layout, and template layout.
The second step is to create a child template that inherits the parent template through the built-in function {extends}.
In the third step, if you need to overwrite the contents of the parent template, you need to implement it through the built-in function {block}, which needs to be used in both the parent template and the child template.
Pay attention to the details
1, Layout page can have many blocks, child page can also have many blocks, through the Name property to associate.
2, the child page in addition to extends and block other content does not show
3, Layout page block can have the default content, the child page does not realize directly display, the implementation is covered.
4, layout page block can be nested with each other, the implementation of the child can be targeted.
5. {$smarty. block.child} layout can invoke the contents of the child, {$smarty. block.parent} child pages can invoke the parent page content
extends.php (back end):
<?php
include "libs/smarty.class.php";
$smarty = new Smarty ();
$smarty->template_dir = "Templates";
$smarty->compile_dir = "Templates_c";
$smarty->display (' Order.tpl ');
$smarty->display (' List.tpl ');
layout.tpl (Parent template page (view master page)):
<! DOCTYPE html>
order.tpl (Child template page, on: Left/right: Bottom layout structure):
{Extends file = ' Layout.tpl '} {* Child template page (content page), extends Inherits parent template (View master page) *}
{Block name = ' main '} The {* Block overrides the corresponding block in the parent template (View master page). The uncovered block is based on the parent template's output *}{* overwrite block (main) implementation: The next layout structure *}
<div class= "main" >
order content
</div>
{/block}
list.tpl (Sub Template page, on:: Bottom layout structure):
{Extends file = "Layout.tpl"}
{Block name = ' content '} {* Overlay block (content) implementation: The layout structure under: *}
<div class= "Content" >
Product List Contents
</div>
{/block}