Smarty Template Inheritance

Source: Internet
Author: User

Template inheritance is more convenient than using the Include method, which is to facilitate the introduction of different CSS JS files on each page;

LAYOUT.TPL (parent template)

 

MYPROJECT.TPL (sub-template)

{extends file= ' layout.tpl '} {Block Name=head} <link href= "/css/mypage.css" rel= "stylesheet" type= "Text/css"/> <script src= "/js/mypage.js "></script>{/block}

Mypage.tpl (grandson Template)

{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 content is here {/block}

Show the above template:

$smarty->display (' Mypage.tpl ');

Alternatively, instead of using {extends} inheritance in a template, you can inherit by defining an inheritance tree within PHP, using the extends: resource type.

The following code returns the same result as the example above:

<?php$smarty->display (' Extends:layout.tpl|myproject.tpl|mypage.tpl ');?>


Smarty Template Inheritance

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.