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.
{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 as the name. All {capture} commands must be paired with {/capture}. You can nest capture commands.
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 |
Caution |
Be careful when capturing {insert} output. If you have caching enabled and you have {insert} commands that you expect to run within cached content, do not capture this content. |
Example 7-2. capturing content to a variable This example also demonstrates the {popup} function
|
See also $smarty.capture, {eval}, {fetch}, fetch() and {assign}.