local

Synopsis

<#local name=value>
or
<#local name1=value1 name2=value2 ... nameN=valueN>
or
<#local name>
  capture this
</#local>

Where:

Description

It is similar to assign directive, but it creates or replaces local variables. This only works inside macro definitions and function definitions.

For more information about variables, read this: Template Author's Guide/Miscellaneous/Defining variables in the template

Note:

A frequent mistake is trying to use assign to change a local variable like: <#macro m><#local x = 1>${x}<#assign x = 2>${x}</#macro>. This prints 11, not 12, because assign creates/replaces the x of the namespace that the template belongs to, and doesn't change the x local variable. Local variables should be always set with the local directive, not just for the fist time.

上一章 首页 下一章