capture函數(shù)
capture函數(shù)
使用方式:
任何在 {capture name="foo"}和{/capture}之間的數(shù)據(jù)將被存儲(chǔ)到變量$foo中,該變量由name屬性指定.
在模板中通過(guò)
$smarty.capture.foo 訪問(wèn)該變量.
如果沒(méi)有指定 name 屬性,函數(shù)默認(rèn)將使用 "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