Comunitatea PHP Romania
 

 
Built-in Functions

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 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. {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 {popup} function

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

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

Ultimele discutii in forum RSS Forum

Ultimele articole Ultimele articole

Top membri

Pirahna Pirahna
acasa , in pat
carco carco
Bucuresti
Birkoff Birkoff
Bucuresti
Mascka Mascka
Braila
raul_ raul_
whooper whooper
Toronto ON
mihaitha mihaitha
Sibiu
gabysolomon gabysolomon
Bacau
oriceon oriceon
Constanta
garlicinicolae garlicinicolae

Newsletter


Email:
 inscriere
 renuntare
 
 Arhiva newsletter

Parteneriat

Copyright © 2001-2008 PHP Romania Add PHPRomania to Google Add PHPRomania to Del.icio.us Add PHPRomania to Stumbleupon Add PHPRomania to Yahoo! Add PHPRomania to Digg Add PHPRomania to Blink Sewing | Mortgage Calculator | Repair Bad Credit | Comcast | MPAA
Ads: Partener Way2Web Nework: gazduire web | inregistrare domenii | web design | imobiliare | web hosting
Powered by Simplis