سؤال

how to access main namespace variable in macro?

I have a macro file called orderMacro.ftl, and import it in test.ftl like this:

<#import "path/orderMacro.ftl" as order/>

I also define a variable in test.ftl:

<#assign orderType="normal"/>

Now I access orderType variable in orderMacro using main.orderType, main means the namespace created for test.ftl(maybe I misunderstand this word). it reports an error: Expression main is undefined

هل كانت مفيدة؟

المحلول

You need to write .main.orderType. Note the initial dot. It's the syntax for accessing "special variables", so that they can't clash with other variables.

نصائح أخرى

Assign it using global

http://freemarker.org/docs/ref_directive_global.html

<#global orderType="normal"/>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top