Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store


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.


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:


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 54. Simple assignment


The value of $name is {$name}.


The above example will output:

The value of $name is Bob.


Example 55. Assignment with math



Example 56. Assignment of an array element



Example 57. Assignment of an multidimensional array element



Example 58. Appending an array



Example 59. 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 *}


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

See also {assign} and {append}

Smarty Template Engine