mirror of
				https://github.com/smarty-php/smarty.git
				synced 2025-11-03 22:01:36 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			123 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
			
		
		
	
	
			123 lines
		
	
	
		
			3.4 KiB
		
	
	
	
		
			XML
		
	
	
	
	
	
<?xml version="1.0" encoding="iso-8859-1"?>
 | 
						|
<!-- $Revision$ -->
 | 
						|
<sect1 id="language.function.capture">
 | 
						|
 <title>{capture}</title>
 | 
						|
 <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>
 | 
						|
 <para>
 | 
						|
  {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 <link
 | 
						|
   linkend="language.variables.smarty.capture">$smarty.capture.foo</link>
 | 
						|
  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.
 | 
						|
 </para>
 | 
						|
 <note>
 | 
						|
  <title>Technical Note</title>
 | 
						|
  <para>
 | 
						|
   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.
 | 
						|
  </para>
 | 
						|
 </note>
 | 
						|
 <caution>
 | 
						|
  <para>
 | 
						|
   Be careful when capturing <link
 | 
						|
   linkend="language.function.insert">{insert}</link>
 | 
						|
   output. If you have
 | 
						|
   <link linkend="caching">caching</link>
 | 
						|
   turned on and you have
 | 
						|
   <link linkend="language.function.insert">{insert}</link>
 | 
						|
   commands that you expect to run
 | 
						|
   within cached content, do not capture this content.
 | 
						|
  </para>
 | 
						|
 </caution>
 | 
						|
 <para>
 | 
						|
  <example>
 | 
						|
   <title>capturing template content</title>
 | 
						|
   <programlisting>
 | 
						|
<![CDATA[
 | 
						|
{* we don't want to print a table row unless content is displayed *}
 | 
						|
{capture name=banner}
 | 
						|
  {include file="get_banner.tpl"}
 | 
						|
{/capture}
 | 
						|
 | 
						|
{if $smarty.capture.banner ne ''}
 | 
						|
<table>
 | 
						|
<tr>
 | 
						|
  <td>
 | 
						|
   {$smarty.capture.banner}
 | 
						|
  </td>
 | 
						|
</tr>
 | 
						|
</table>
 | 
						|
{/if}
 | 
						|
]]>
 | 
						|
   </programlisting>
 | 
						|
  </example>
 | 
						|
 </para>
 | 
						|
 <para>
 | 
						|
  See also
 | 
						|
  <link
 | 
						|
   linkend="language.variables.smarty.capture">$smarty.capture</link>,
 | 
						|
   <link linkend="language.function.eval">{eval}</link>,
 | 
						|
  <link linkend="language.function.fetch">{fetch}</link>,
 | 
						|
  <link linkend="api.fetch">fetch()</link>
 | 
						|
  and <link linkend="language.function.assign">{assign}</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
 | 
						|
--> |