Not a developer? Go to



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.


  • var or name: 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

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

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, always Var and I know that I’ve used the op attribute a number of times before although I will say I usually do it this way:

 <mt:var name="whatevers" op="++" setvar="whatevers">

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 with op and value, that’s a bug and should be fixed immediately if it has not yet been, and SetVar should be re-deprecated.

Leave a Comment