Capture instruction collects the output of the template into a special block instead of displaying it. The captured content can be used in template from the special block $opt.capture.foo where "foo" is the name of captured content. The instruction takes one parameter:
Table 2.9. Capture: parameters
| Name | Type | Required? | Description |
|---|---|---|---|
| name | ID | Yes | The name of captured content. |
Example 2.56. Capturing the content
{* we don't want to print a table row unless content is displayed *}
{capture=banner}
{include file="`get_banner.tpl`"}
{/capture}
{if $opt.capture.banner ne ""}
<table>
<tr>
<td>
{$opt.capture.banner}
</td>
</tr>
</table>
{/if}If you are also a programmer, you can capture whole templates in your application using optClass::parseCapture() method.
Capture instructions can be nested. In this way the output is directed to the last opened capture block:
Example 2.57. Nested captures
{capture=foo1}
<p>Aaa</p>
{capture=foo2}
<p>Bbb</p>
{/capture}
<p>Ccc</p>
{/capture}
{$opt.capture.foo1}
{$opt.capture.foo2}The script output will be:
Aaa Ccc Bbb