kaola-fed / freemarker

Freemarker integration for NodeJS
MIT License
26 stars 17 forks source link

this library does NOT support global variable access within the imported file #12

Open nykevinwong opened 5 years ago

nykevinwong commented 5 years ago

when importing a FTL file using import keyword, this freemarker library does not recognize that the global variable, which are already accessible within the host file, shall be accessible within imported file as well.

for example, below host file can access currentObject as global variable, but the same global variable can NOT be accessed within imported file "utilities.ftl".

host.ftl <#assign metadata = currentObject.attributes.meta! > <#assign attributes = currentObject.attributes!>

<#import "../../macros/utilities.ftl" as utilities> <#include "../../components/identity.ftl" >

utilities.ftl <#assign roles= currentObject.attributes.roles>

Error: >>> ABORTED! <<<

The cause of aborting was: FreeMarker template error: The following has evaluated to null or missing: ==> currentObject [in template "macros/utilities.ftl" at line 9, column 22]


Tip: If the failing expression is known to legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing</#if>. (These only cover the last st ep of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)??


FTL stack trace ("~" means nesting-related):

int64ago commented 5 years ago

PR welcome, for we don't use this in our work anymore.