<mt:SetVarBlock>

A block tag used to set the value of a template variable. Note that you can also use the global 'setvar' modifier to achieve the same result as it can be applied to any MT tag.

Attributes:

  • var or name (required)

    Identifies the name of the template variable. See Var for more information on the format of this attribute.

  • 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.

This page was last updated on 2008-05-24, 06:01.  

2 Notes

Note that the <SetVarBlock> preserves linefeeds. Using the block function as shown in the example above will put linefeeds into 'foo', so that you get LF(variable value)LF.

If your variable result is, say, the number 9, and you use the syntax in the example above, you will get:

LF
9
LF

In a certain situation, if you compare the generated value (using <mt:if> or <mt:unless>), the result will be incorrect.

To generate a variable value without linefeeds, use the following, all in one line:

<mt:setvarblock name="foo"><mt:foldercount></mt:setvarblock>

To strip linefeeds, use the strip_linefeeds modifier, like so:

<mt:setvarblock name="foo" strip_linefeeds="1">
    <mt:VariablesHereWhichCanNotBeSetWithMTVar>
</mt:setvarblock>

Thanks to Chris Hall for the heads up on this!

Gautam, what's a linefeed?

Leave a note

Have a question, please use the MT Forums. Notes sumbitted here should pertain to tips & hints regarding documentation. Your note may be removed once it's contents has be integrated into the body of the page.