[PHP]-How to Use the smarty master (similar to the ASP. NET master)

Source: Internet
Author: User

Source: http://www.flyy.info/480.html

Those who have used the master pages of Asp.net should feel that this thing is worth learning from PHP.
The new smarty 3 introduces the concept of template inheritance, which can implement the same functions as the master page of Asp.net.

Template inheritance example

Layout. TPL (parent)

 <  Html  >  
< Head >
< Title > {Block name = title} default page title {/block} </ Title >
{Block name = head} {/block}
</ Head >
< Body >
{Block name = body} {/block}
</ Body >
</ Html >

Myproject. TPL (child)

{Extends file = 'layout. TPL '}
{Block name = head}
<LinkHref= "/CSS/mypage.css"REL= "Stylesheet"Type= "Text/CSS"/>
<ScriptSRC= "/JS/mypage. js"> </Script>
{/Block}

Mypage. TPL (grandchild)

{Extends file = 'myproject. TPL '}
{Block name = title} My page title {/block}
{Block name = head}
< Link Href = "/CSS/mypage.css" REL = "Stylesheet" Type = "Text/CSS" />
< Script SRC = "/JS/mypage. js" > </ Script >
{/Block}
{Block name = body} My HTML page body goes here {/block}

To render the above use

 
$ Smarty->Display ('Mypage. TPL');

The resulting output is

 <  Html  >  
< Head >
< Title > My page title </ Title >
< Link Href = "/CSS/mypage.css" REL = "Stylesheet" Type = "Text/CSS" />
< Script SRC = "/JS/mypage. js" > </ Script >
</ Head >
< Body >
My HTML page body goes here
</ Body >
</ Html >
Related Article

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.