Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between assign and local in freemarker

Tags:

freemarker

For instance:

<#assign foo="foo"/>
<#local bar="bar"/>

When should one be used instead of the other

like image 453
OscarRyz Avatar asked Mar 10 '23 09:03

OscarRyz


1 Answers

#local creates or replaces a variable that lives in the scope of the ongoing macro or function call, and thus is used inside a #macro or #function.

#assign creates or replaces a variable in the current namespace (or in the explicitly designated namespace via in somenamespace). If you don't use multiple namespaces (ie., you don't use #import) then you can think of them as global variables.

See also:

  • Kinds of variables: http://freemarker.org/docs/dgui_misc_var.html

  • Namespaces: http://freemarker.org/docs/dgui_misc_namespace.html

like image 67
ddekany Avatar answered Mar 23 '23 15:03

ddekany