capture函數(shù)
capture函數(shù)
使用方式:
##任何在{capture name="foo" }和{/capture}之間的資料將被儲(chǔ)存到變數(shù)$foo中,該變數(shù)由name屬性指定.在模板中通過(guò)
$smarty.capture.foo 存取該變數(shù).
如果沒(méi)有指定 name 屬性,函數(shù)預(yù)設(shè)會(huì)使用 "default"
作為參數(shù).
{capture}必須成對(duì)出現(xiàn),即以{/capture}作為結(jié)尾,函數(shù)不能嵌套使用
eg:
test.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>{#pageTitle#}</title> </head> <body> {capture name=banner} {include file="./test1.html"} {/capture} {$smarty.capture.banner} </body> </html>
test1.html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> 1111111111111111 </body> </html>
運(yùn)行結(jié)果:
1111111111111111