Smarty Template engine _9-smarty template inheritance features

Source: Internet
Author: User
Tags inheritance smarty template

Child template Inherits Parent template

1, through the <{extends}> tag inheritance

<{extends file= ' parent.html '}>

Must be written in the first row of the child template, and all subsequent content will be ignored


Overwrite the contents of the parent template or append to the child template

Overwrite the contents of the parent template

<{block name= ' title '}>
The contents of a child template
<{/block}>

Will overwrite the contents of the block with the same name in the parent template (name= ' title ')

<{block name= ' title '}>
Content in the parent template
<{/block}>


Append content to the parent template in a child template

<{extends file= ' parent.html '}>
<{block name= ' title ' Prepend}>
	I was appended to the previous content--
<{/block} >
<{block name= ' content ' append}>
	<br/>--I was appended at the back

Prepend will append the contents of the child template block to the front of the contents of the same block in the parent template

Append is appended to the back

prepend and append can act on the same block at the same time


Block Content1 in the parent template above, no content defined,

<{$smarty .block.child}> indicates that the contents of the block with the same name in the child template will be displayed

<{block name= ' title '}>
newly added--<{$smarty .block.parent}>
<{/block}>
Similarly, "newly added--<{$smarty .block.parent}>" in a child template

Indicates that the content in the block is "newly added-(plus content in a block of the same name in the parent template)"

Similar to extends <{include file= ' parent.html '}>


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.