SetVar
A function tag used to set the value of a template variable.
For simply setting variables you can use the Var tag with a value attribute to assign template variables.
Attributes
var
orname
: Identifies the name of the template variable. See Var for more information on the format of this attribute.value
: The value to assign to the variable.op
(optional): See the Var tag for more information about this attribute.prepend
(optional): If specified, places the contents at the front of any existing value for the template variable.append
(optional): If specified, places the contents at the end of any existing value for the template variable.
Chad Everett on July 29, 2009, 3:35 p.m. Reply
One note about using SetVar - though the details above would lead you to believe that if you use the value attribute you can replace it with Var. You would not always be correct.
The problem appears to stem from the use of the op attribute.
Say for instance you use something like op=”add” value=”1” - you would think since you used value in there, you could use Var. Not. Stick with SetVar.
If you only use value, it’s generally safe to use Var. But just make sure you check the output.
Jay Allen on October 30, 2009, 2:10 a.m. Reply
Chad, are you absolutely sure that that is true as of v4.23 and above? I never use
SetVar
, alwaysVar
and I know that I’ve used theop
attribute a number of times before although I will say I usually do it this way:And yes, having to use
setvar
when I’ve specified++
annoys me given that in perl (and others?)++
specifically means increment the internal value.Regardless, if
Var
doesn’t play nice withop
andvalue
, that’s a bug and should be fixed immediately if it has not yet been, andSetVar
should be re-deprecated.