|
|
|
|
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| Attribute Name | Type | Required | Default | Description |
|---|
| name | string | no | default | The name of the captured block | | assign | string | No | n/a | The variable name where to assign the captured output to |
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. All {capture} commands must
be paired with {/capture}. You can nest capture commands.
Technical Note:
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.
| Caution |
Be careful when capturing insert output. If
you have caching turned on 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 ""}
<tr>
<td>
{$smarty.capture.banner}
</td>
</tr>
{/if} |
|
|
|
|
|
|
|
|
|
Disclaimers: This
document is provided as free service for the benefits of Active-Venture.com's web hosting customers only. |
|
|
|
Quotes: True happiness, we are told, consists in getting out of one's self, but the point is not only to get out, you must stay out; and to stay out you must have some absorbing errand.There are two kinds of taste, the taste for emotions of surprise and the taste for emotions of recognition.Live all you can; it's a mistake not to. It doesn't so much matter what you do in particular, so long as you have your life. If you haven't had that what have you had?
|
|
|
|
|