mirror of
https://github.com/smarty-php/smarty.git
synced 2025-11-02 21:31:48 +01:00
136 lines
4.1 KiB
XML
136 lines
4.1 KiB
XML
<?xml version="1.0" encoding="iso-8859-1"?>
|
|
<!-- $Revision$ -->
|
|
<sect1 id="language.function.capture">
|
|
<title>{capture}</title>
|
|
|
|
<para>
|
|
<varname>{capture}</varname> is used to collect the output of the template between the
|
|
tags into a variable instead of displaying it. Any content between
|
|
<varname>{capture name='foo'}</varname> and <varname>{/capture}</varname> is collected
|
|
into the variable specified in the <parameter>name</parameter> attribute.
|
|
</para>
|
|
<para>The captured content can be used in the
|
|
template from the variable <link
|
|
linkend="language.variables.smarty.capture"><parameter>$smarty.capture.foo</parameter></link>
|
|
where <quote>foo</quote> is the value passed in the <parameter>name</parameter> attribute.
|
|
If you do not supply the <parameter>name</parameter> attribute, then <quote>default</quote> will
|
|
be used as the name ie <parameter>$smarty.capture.default</parameter>.
|
|
</para>
|
|
<para><varname>{capture}'s</varname> can be nested.
|
|
</para>
|
|
|
|
|
|
<informaltable frame="all">
|
|
<tgroup cols="5">
|
|
<colspec colname="param" align="center" />
|
|
<colspec colname="type" align="center" />
|
|
<colspec colname="required" align="center" />
|
|
<colspec colname="default" align="center" />
|
|
<colspec colname="desc" />
|
|
<thead>
|
|
<row>
|
|
<entry>Attribute Name</entry>
|
|
<entry>Type</entry>
|
|
<entry>Required</entry>
|
|
<entry>Default</entry>
|
|
<entry>Description</entry>
|
|
</row>
|
|
</thead>
|
|
<tbody>
|
|
<row>
|
|
<entry>name</entry>
|
|
<entry>string</entry>
|
|
<entry>no</entry>
|
|
<entry><emphasis>default</emphasis></entry>
|
|
<entry>The name of the captured block</entry>
|
|
</row>
|
|
<row>
|
|
<entry>assign</entry>
|
|
<entry>string</entry>
|
|
<entry>No</entry>
|
|
<entry><emphasis>n/a</emphasis></entry>
|
|
<entry>The variable name where to assign the captured output to</entry>
|
|
</row>
|
|
</tbody>
|
|
</tgroup>
|
|
</informaltable>
|
|
|
|
|
|
<caution>
|
|
<para>
|
|
Be careful when capturing <link
|
|
linkend="language.function.insert"><varname>{insert}</varname></link>
|
|
output. If you have
|
|
<link linkend="caching"><parameter>$caching</parameter></link>
|
|
enabled and you have
|
|
<link linkend="language.function.insert"><varname>{insert}</varname></link>
|
|
commands that you expect to run
|
|
within cached content, do not capture this content.
|
|
</para>
|
|
</caution>
|
|
<para>
|
|
<example>
|
|
<title>{capture} with a the name attribute</title>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{* we don't want to print a div tag unless content is displayed *}
|
|
{capture name=banner}
|
|
{include file='get_banner.tpl'}
|
|
{/capture}
|
|
|
|
{if $smarty.capture.banner ne ''}
|
|
<div id="banner">{$smarty.capture.banner}</div>
|
|
{/if}
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
<example>
|
|
<title>{capture} into a template variable</title>
|
|
<para>This example also demonstrates the
|
|
<link linkend="language.function.popup"><varname>{popup}</varname></link>
|
|
function</para>
|
|
<programlisting>
|
|
<![CDATA[
|
|
{capture name=some_content assign=popText}
|
|
The server is {$smarty.server.SERVER_NAME|upper} at {$smarty.server.SERVER_ADDR}<br>
|
|
Your ip is {$smarty.server.REMOTE_ADDR}.
|
|
{/capture}
|
|
<a href="#" {popup caption='Server Info' text=$popText}>help</a>
|
|
]]>
|
|
</programlisting>
|
|
</example>
|
|
|
|
|
|
</para>
|
|
<para>
|
|
See also
|
|
<link
|
|
linkend="language.variables.smarty.capture"><parameter>$smarty.capture</parameter></link>,
|
|
<link linkend="language.function.eval"><varname>{eval}</varname></link>,
|
|
<link linkend="language.function.fetch"><varname>{fetch}</varname></link>,
|
|
<link linkend="api.fetch"><varname>fetch()</varname></link>
|
|
and <link linkend="language.function.assign"><varname>{assign}</varname></link>.
|
|
</para>
|
|
</sect1>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"../../../../manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
--> |