w3-tools.com - Free Webmaster Tools and Resources
 
w3-tools.com - Free Webmaster Tools and Resources
 Free Webmaster Tools and Resources

 



Smarty Manual

This manual is provided as a courtesy. It is not an official source. Please check smarty.php.net for updated information.

Smarty Manual

Smarty Manual

Chapter 8. Custom Functions

Smarty comes with several custom functions that you can use in the templates.

{assign}

{assign} is used for assigning template variables during the execution of the template.

Attribute NameTypeRequiredDefaultDescription
varstringYesn/aThe name of the variable being assigned
valuestringYesn/aThe value being assigned

Example 8-1. {assign}

{assign var="name" value="Bob"}

The value of $name is {$name}.

The above example will output:

The value of $name is Bob.

Example 8-2. Accessing {assign} variables from a PHP script.

To access {assign} variables from php use get_template_vars(). However, the variables are only available after/during template execution as in the following example

{* index.tpl *}
{assign var="foo" value="Smarty"}
<?php

// this will output nothing as the template has not been executed
echo $smarty->get_template_vars('foo');

// fetch the template to a dead variable
$dead $smarty->fetch('index.tpl');

// this will output 'smarty' as the template has been executed
echo $smarty->get_template_vars('foo');

$smarty->assign('foo','Even smarter');

// this will output 'Even smarter'
echo $smarty->get_template_vars('foo');

?>

The following functions can also optionally assign template variables.

{capture}, {include}, {include_php}, {insert}, {counter}, {cycle}, {eval}, {fetch}, {math}, {textformat}

See also assign() and get_template_vars().

Newsletter

Join to our newsletter and receive news and updates about our site.
Your name: 
E-mail address: 
Action: 
 

Hosted by

Search

Google
Web w3-tools.com

Links

  What is my IP? Find your IP address!     Valid XHTML 1.0 Transitional  
Copyright © 2006. by w3-tools.com. All rights reserved