Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Freemarker: difference between include and import?

Tags:

freemarker

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

I don't really understand why I should use include vs import.

like image 762
user Avatar asked Mar 02 '16 07:03

user


1 Answers

#include is very much like if you copy-paste the content of the included file into the place of the #include tag. #import also processes the target file, but doesn't output anything. Instead, it assigns the set of variables (the namespace) created by the imported template to the variables after the as keyword. As #macro-s and #function-s just create variables, #import is practical for pulling in a collection of utility macros and functions. Also note that #import-ing the same file for the second time does nothing (as the namespace is only populated once), while calling #include twice will process the target file twice.

As for JavaScript, FreeMarker runs on the server side, and the JavaScript runs in the browser. So the browser only ever sees the final output from FreeMarker.

like image 147
ddekany Avatar answered Oct 23 '22 12:10

ddekany