◇ in order to make many pages ' head ' and ' foot ' development maintenance convenient, we make a layout page, other specific business pages to populate the ' Layout ' page.
◇ can be divided into ' on ', ' under ' The layout, ' on ' is ' head ', Next is ' tail ', ' in ' to write business logic. It is very convenient to maintain.
◇ You can create a layout file ' layout.html ' and put it in the./templates folder with the following code:
1 < Div > Header information </div>2{block name= "main"}3{/ Block}4<Div> Trailing info </Div >
Note: The ' header information ' and ' tail information ' can be written according to the needs of the front-end personnel.
◇ then create a ' index.html ', also placed in the./templates folder, the code is as follows:
1 {extends file= "layout.html"} 2 {block name= "main"}<Div> middle section </div>{ /block}
Note: 1, the first line {extends file= "layout.html"} is the meaning of inheritance, inherited from layout.html
2. XXX in {block name= "xxx"}{/block} in the second row is consistent with name in {block name= "xxx"} in the layout file
◇ finally create a index.php file to refer to this template (reference Smarty,display ...). The code is as follows:
1 <? PHP 2 Header ("Content-type:text/html;charset=utf-8"); 3 include "./libs/smarty.class.php"; 4 $smarty New Smarty; 5 $smarty , display ("index.html"); 6 ? >
◇ Layout Extension:
◇ Layout inheritance use note points:
◇ Layout page can have many blocks, their own pages can also have many blocks, they are associated with the Name property
◇ sub-pages except extends and block other content not to show
◇ The block of the layout page can have the default content, the child page does not implement the direct display. If the child page implements the {block} content that overrides the parent page
◇ Layout page block can be nested with each other, their implementation can be targeted implementation.
◇{$smarty. Block.child} layouts can invoke the contents of children, {$smarty. block.parent} child pages can invoke parent page content
PHP Essay---smarty template engine layout/inheritance Use