Older Newer
Thu, 02 Apr 2009 18:27:55 . . . . (jLix.net)?

Changes by last author:

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 http://jlix.net/extensions/smarty/var

* @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: http://jlix.net/extensions/smarty/var

Discussion in Smarty forum: http://www.phpinsider.com/smarty-forum/viewtopic.php?t=15196

This is definitely not the first plugin of its kind (same functionality as http://smarty.incutio.com/?page=SetVars, but with a slightly different syntax/implementation). You decide which to choose.