API / Apache FreeMarker Interview questions
What is the difference between #assign and #global?
#assign creates or updates a variable in the current namespace - the template that contains the tag, or the calling template's namespace if used inside an #included file. #global instead creates a variable in FreeMarker's single global namespace, which is visible from every template and macro in that processing run, regardless of how deeply nested the call is.
<#assign pageTitle = "Dashboard"> <#-- local to this namespace --> <#global debugMode = true> <#-- visible everywhere -->
Because a global variable can be set and read from anywhere, it is easy to overuse and create hidden coupling between unrelated templates; most style guides reserve #global for a small number of clearly cross-cutting flags rather than everyday values.
More Related questions...