Smarty comes with several built-in functions. Built-in functions are integral to the template language. You cannot create custom functions with the same names, nor can you modify built-in functions.
Smarty 擁有一些內建函式,這些內建函式可以與樣板語言作結合,你無法創造出與這 些內建函式相同名字的函式或是修改這些內建函式。
| Attribute Name | Type | Required | Default | Description |
|---|---|---|---|---|
| name | string | no | default | The name of the captured block |
| assign | string | No | n/a | The variable name where to assign the captured output to |
capture is used to collect the output of the template into a variable instead of displaying it. Any content between {capture name="foo"} and {/capture} is collected into the variable specified in the name attribute. The captured content can be used in the template from the special variable $smarty.capture.foo where foo is the value passed in the name attribute. If you do not supply a name attribute, then "default" will be used. All {capture} commands must be paired with {/capture}. You can nest capture commands.
capture 函式會取得樣版的輸出並給變數,而不會真的將這些輸出的內容展示出 來。在 {capture name="foo"} 與 {/capture} 之間的內容會設定給 name 的屬性所指的值,而 我們可以用變數 $smarty.capture.foo 將取得的內容使用在樣版中,其中 foo 是剛剛 name 的 屬性。如果你沒有指定 name 的屬性的話,則預設值為 "default"。所有的 {capture} 都必須與 {/capture} 成對,且不可以巢狀使用 capture 命令。
Technical Note: Smarty 1.4.0 - 1.4.4 placed the captured content into the variable named $return. As of 1.4.5, this behavior was changed to use the name attribute, so update your templates accordingly.
技術提醒: Smarty 1.4.0 - 1.4.4 會把取得的內容放在變數 $return 中,而在 1.4.5 版中會將取 得的內容放在 name 的屬性裡,所以請根據你的 Smarty 版本將樣板作更新。
| Caution |
Be careful when capturing insert output. If you have caching turned on and you have insert commands that you expect to run within cached content, do not capture this content. 請小心處理使用 insert 所取得的輸出結果。如果你有將快取打開,且希望對這些被快取記得的內容使用 insert 指令的話,請不要使用 capture 取得這些內容。 |