Capture can be used to store everything between the beginning of the capture tag and the end tag in a variable.
capture
{{capture}}.... {{/capture}}
Arguments
The following arguments can be used with capture:
Argument | Description |
---|
name | The name of the capture, default is "default". The name of the capture can be used to display the content of the capture: {{$smarty.capture.<name>}} |
assign | The name of the variable in which the content should be stored. |
append | The variable to be appended to the capture. |
Examples
capture
{{capture}}We are going to store this text in a variable using the capture tag.{{/capture}}
{{$smarty.capture.default}}
Output:
We are going to store this text in a variable using the capture tag.
{{capture assign="tekst"}}In this case, we assign a variable to the capture directly.{{/capture}}
{{$tekst}}
Output:
In this case, we assign a variable to the capture directly.
Capture can also be used to build a list of data:
capture array
{{capture append="array"}}value1{{/capture}}
{{capture append="array"}}value2{{/capture}}
{{capture append="array"}}value3{{/capture}}
<pre>{{$array|print_r}}</pre>
Output:
Array
(
[0] => value1
[1] => value2
[2] => value3
)