Get Smarty

Donate

Donate Bitcoin Bitcoin
Paypal

Smarty Icon

You may use the Smarty logo according to the trademark notice.

Smarty Template Engine Smarty Template Engine

For sponsorship, advertising, news or other inquiries, contact us at:

Sites Using Smarty

Largest classified with thousands of ads at Shoppok

Buy cheap eyeglasses from Cheapglasses123.com and save up to 80%.

Buy prescription glasses from www.australiaglasses.com and save.

Cheap Glasses Now On Sale at GlassesPeople.com. Starts At $7.95.

Where to buy discount wedding dresses and cheap smart dresses free shipping - Weddingdresstrend.com

Find Wedding Dresses Online at Canada from Ca-dresses.com

Find your local domestic cleaner

Brautkleider auf Topwedding.de

Best Wedding Dresses Australia at AuBridalDresses.com

Find free files to download on allwhatyouwant.net

Advertisement

Chapter 7. Built-in Functions

Smarty comes with several built-in functions. These built-in functions are the integral part of the smarty template engine. You cannot create your own custom functions with the same name; and you should not need to modify the built-in functions.

A few of these functions have an assign attribute which collects the result the function to a named template variable instead of being output; much like the {assign} function.

{capture}

{capture} is used to collect the output of the template between the tags 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 variable $smarty.capture.foo where foo is the value passed in the name attribute. If you do not supply the name attribute, then default will be used as the name ie $smarty.capture.default.

{capture}'s can be nested.

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

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. {capture} with the name attribute


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

   


Example 7.2. {capture} into a template variable

This example also demonstrates the upper modifier


{capture name=some_content assign=addrText}
The server is {$smarty.server.SERVER_NAME|upper} at {$smarty.server.SERVER_ADDR}<br>
Your ip is {$smarty.server.REMOTE_ADDR}.
{/capture}
{$addrText}

     


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

Comments
No comments for this page.
Post a Comment
All comments are moderated. Support questions are ignored, use the forums instead.
Author:
Email: (not shown)
What is 20 plus 16? (Are you human?)

Advertisement

Sponsors [info]

UK Web Hosting @webhost.uk.net
Best Web Hosting @rshosting.com
Web Hosting UK @webhostinguk.com
Unlimited Web Hosting @infrenion.com
App Entwicklung @morphodo.com
GoDaddy Coupon @buy-hosting.net
First Click Internet Marketing @fcinternetmarketing.com