PHP Essay---smarty template engine layout/inheritance Use

Source: Internet
Author: User
Tags smarty template

◇ 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.