Freemarker: the difference between inclusion and import?

I am trying to create two templates and use the variables of one file .ftl(freemarker) in another.

I do not understand why I have to use includevs import.

+4
source share
1 answer

#includevery similar if you copy the contents of the attached file to the tag location #include. #importalso processes the target file but does not output anything. Instead, it assigns variables (namespace) created by the imported template to the variables after the keyword as. Since #macro-s and #function-s simply create variables, it is #importpractical for pulling out a collection of macros and utility functions. Also note that #import- the same file does nothing the second time (since the namespace is filled only once), and the call #includewill process the target file twice twice.

Like JavaScript, FreeMarker works on the server side, and JavaScript works in the browser. Therefore, the browser only ever sees the final output from FreeMarker.

+12

All Articles