w3-tools.com - Free Webmaster Tools and Resources
 
w3-tools.com - Free Webmaster Tools and Resources
 Free Webmaster Tools and Resources

 



Smarty Manual

This manual is provided as a courtesy. It is not an official source. Please check smarty.php.net for updated information.

Smarty Manual

Smarty Manual

Chapter 7. Built-in Functions

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}

{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 NameTypeRequiredDefaultDescription
namestringnodefaultThe name of the captured block
assignstringNon/aThe 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-1. capturing template content

{* 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}

Example 7-2. capturing content to a variable

This example also demonstrates the {popup} function

{capture name=some_content assign=popText}
    .... some content ....
  {/capture}
  
  <a href="#" {popup caption='Help' text=$popText}>help</a>

See also $smarty.capture, {eval}, {fetch}, fetch() and {assign}.

Newsletter

Join to our newsletter and receive news and updates about our site.
Your name: 
E-mail address: 
Action: 
 

Hosted by

Search

Google
Web w3-tools.com

Links

  What is my IP? Find your IP address!     Valid XHTML 1.0 Transitional  
Copyright © 2006. by w3-tools.com. All rights reserved