The {var} function assigns values to template variables in a more intuitive and brief manner than Smarty's default {assign} function. Multiple variables can be assigned in one {var} statement.

Instead of writing:

{assign var="welcome" value="Hello world!"}
{assign var="foo" value="bar"}

you can just write:

{var welcome="Hello world!" foo="bar"}

Plugin code:

 * Smarty {var} plugin
 * Type:       function
 * Name:       var
 * Date:       Mar 30, 2009
 * Purpose:    Assign values to template variables in a more intuitive manner than {assign}
 * Syntax:     {var welcome="Hello world!"}: assign "Hello World!" to $welcome
 *             In one {var} statement values can be assigned to multiple variables
 * Install:    Drop into the plugin directory
 * @link
 * @author     Sander Aarts <smarty at jlix dot net>
 * @copyright  2009 Sander Aarts
 * @license    LGPL License
 * @version    1.0
 * @param      array
 * @param      Smarty
function smarty_function_var($params, &$smarty)
    if (count($params)===0) {
        $smarty->trigger_error("{var}: no variables declared");


You can download the plugin from:

Discussion in Smarty forum:

This is definitely not the first plugin of its kind (same functionality as, but with a slightly different syntax/implementation). You decide which to choose.