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

Find free files to download on allwhatyouwant.net

Looking For Affordable Wedding Dresses 2015 at Best Prices On TDBridal.com

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. They are compiled into corresponding inline PHP code for maximum performance.

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.

{$var=...}

This is a short-hand version of the {assign} function. You can assign values directly to the template, or assign values to array elements too.

Note

Assignment of variables in-template is essentially placing application logic into the presentation that may be better handled in PHP. Use at your own discretion.

The following attributes can be added to the tag:

Attributes:

Attribute Name Shorthand Type Required Default Description
scope n/a string No n/a The scope of the assigned variable: 'parent','root' or 'global'

Option Flags:

Name Description
nocache Assigns the variable with the 'nocache' attribute

Example 7.1. Simple assignment


{$name='Bob'}

The value of $name is {$name}.

  

The above example will output:


The value of $name is Bob.

  

Example 7.2. Assignment with math


{$running_total=$running_total+$some_array[row].some_value}

  

Example 7.3. Assignment of an array element


{$user.name="Bob"}

  

Example 7.4. Assignment of an multidimensional array element


{$user.name.first="Bob"}

  

Example 7.5. Appending an array


{$users[]="Bob"}

  

Example 7.6. Assigment in the scope of calling template

Variables assigned in the included template will be seen in the including template.


{include file="sub_template.tpl"}
...
{* display variable assigned in sub_template *}
{$foo}<br>
...

  

The template above includes the example sub_template.tpl below


...
{* foo will be known also in the including template *}
{$foo="something" scope=parent}
{* bar is assigned only local in the including template *}
{$bar="value"}
...


See also {assign} and {append}

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 6 plus 7? (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
First Click Internet Marketing @fcinternetmarketing.com
Credit Card Processing Company