<$mt: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 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.
Related Tags:

Merv
October 12, 2007 6:33 PM | Reply
Caution! It appears these statements at the beginning of templates outputs blank lines before the Header template. If using any php in the Header before the Doctype, you either need to move the MTInclude Header before the SetVar or put the php code in a MTInclude (or the code itself) before any of the SetVar statements.
MT SetVar (SetVarBlock or SetVarTemplate) should not be creating blank lines in the generated code.
CC
January 10, 2008 8:16 AM | Reply
Merv, I've seen similar behavior with SSI statements. I bet it's not the variable statements that output the line breaks; it's the fact that the variable statments are each on their own line.
In other words, the template contains line breaks between each MT variable statement; after the MT tags are used, the line breaks remain!
So run all your variable tags together. It's harder to read and maintain, but removes your excess line breaks:
<mt:SetVar name="foo1" value="bar" /><mt:SetVar name="foo2" value="bar" /><mt:SetVar name="foo3" value="bar" />
Jay Allen
February 6, 2009 3:43 PM | Reply
A quick note for anyone reading the comments above: This issue was fixed in MT 4.2 for all XML-based templates (i.e. the only ones for which it matters.). At this point, it's merely aesthetic.
If however, you are OCD about your HTML source, you can always wrap your entire template in an mt:Section block and strip the whitespace with a regex.
Example
Chad Everett
July 29, 2009 3:35 PM | 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
October 30, 2009 2:10 AM | Reply
Chad, are you absolutely sure that that is true as of v4.23 and above? I never use
SetVar, alwaysVarand I know that I've used theopattribute a number of times before although I will say I usually do it this way:And yes, having to use
setvarwhen I've specified++annoys me given that in perl (and others?)++specifically means increment the internal value.Regardless, if
Vardoesn't play nice withopandvalue, that's a bug and should be fixed immediately if it has not yet been, andSetVarshould be re-deprecated.