{block}
鍙湪妯℃澘涓婂畾涔変竴鍧楀尯鍩燂紝浠ヨ繘琛屾ā鏉跨户鎵裤傝缁嗗弬瑙妯℃澘缁ф壙.
瀛愭ā鏉夸腑鐨{block}
鍖哄煙浠g爜锛屽皢浼氭浛鎹㈢埗妯℃澘瀵瑰簲鐨勫尯鍩熶唬鐮併
鍙﹀锛{block}
鍙互璁剧疆鎴愬悎骞剁埗瀛愭ā鏉跨殑鐩稿簲鍖哄煙銆傚湪瀛愭ā鏉跨殑{block}
涓畾涔
append
鎴 prepend
锛屽彲浠ヤ娇瀛愭ā鏉块檮鍔犲湪鐖舵ā鏉
{block}
鍖哄煙鐨勫悗闈㈡垨鍓嶉潰銆
鍦{block}
鍐呭涓娇鐢▄$smarty.block.parent}锛屽彲浠ヨ鐖舵ā鏉跨殑鍖哄煙浠g爜鏀惧埌
瀛愭ā鏉{block}
鍐呯殑浠讳綍浣嶇疆銆
{blocks}
鍙互宓屽浣跨敤銆
灞炴:
鍙傛暟鍚嶇О | 绫诲瀷 | 蹇呴夊弬鏁 | 榛樿鍊 | 璇存槑 |
---|---|---|---|---|
name | string | Yes | n/a | 妯℃澘鍖哄煙鐨勫悕绉 |
鍙夊睘鎬 (浠呭湪瀛愭ā鏉夸腑浣跨敤):
鍚嶇О | 璇存槑 |
---|---|
append |
{block} 鍖哄煙浠g爜灏嗛檮鍔犲埌鐖舵ā鏉跨殑{block} 鍐呭涔嬪悗 |
prepend |
{block} 鍖哄煙浠g爜灏嗛檮鍔犲埌鐖舵ā鏉跨殑{block} 鍐呭涔嬪墠 |
hide | 鍦ㄦ病鏈夎鍚嶇О鍖哄煙鐨勬椂鍊欙紝蹇界暐鍖哄煙鍐呭銆 |
nocache | 鍏抽棴{block} 缂撳瓨 |
Example聽7.15.聽绠鍗曠殑 {block}
渚嬪瓙
parent.tpl
<html> <head> <title>{block name="title"}Default Title{/block}</title> <title>{block "title"}Default Title{/block}</title> {* short-hand *} </head> </html>
child.tpl
{extends file="parent.tpl"} {block name="title"} Page Title {/block}
缁撴灉杈撳嚭锛
<html> <head> <title>Page Title</title> </head> </html>
Example聽7.16.聽鍓嶉潰闄勫姞 {block}
渚嬪瓙
parent.tpl
<html> <head> <title>{block name="title"}Title - {/block}</title> </head> </html>
child.tpl
{extends file="parent.tpl"} {block name="title" prepend} Page Title {/block}
缁撴灉杈撳嚭
<html> <head> <title>Title - Page Title</title> </head> </html>
Example聽7.17.聽鍚庨潰闄勫姞 {block}
渚嬪瓙
parent.tpl
<html> <head> <title>{block name="title"} is my title{/block}</title> </head> </html>
child.tpl
{extends file="parent.tpl"} {block name="title" append} Page Title {/block}
缁撴灉杈撳嚭锛
<html> <head> <title>Page title is my titel</title> </head> </html>
Example聽7.18.聽{$smarty.block.child}
渚嬪瓙
parent.tpl
<html> <head> <title>{block name="title"}The {$smarty.block.child} was inserted here{/block}</title> </head> </html>
child.tpl
{extends file="parent.tpl"} {block name="title"} Child Title {/block}
缁撴灉杈撳嚭锛
<html> <head> <title>The Child Title was inserted here</title> </head> </html>
Example聽7.19.聽{$smarty.block.parent}
渚嬪瓙
parent.tpl
<html> <head> <title>{block name="title"}Parent Title{/block}</title> </head> </html>
child.tpl
{extends file="parent.tpl"} {block name="title"} You will see now - {$smarty.block.parent} - here {/block}
缁撴灉杈撳嚭锛
<html> <head> <title>You will see now - Parent Title - here</title> </head> </html>
鍙傝
妯℃澘缁ф壙,
$smarty.block.parent
,
$smarty.block.child
,
鍜 {extends}