API / Apache FreeMarker Interview questions
What is the difference between #include and #import?
Both pull content from another template file, but they do very different things with it.
| Aspect | #include | #import |
| What it produces | Inserts the target template's rendered output inline | Loads the target as a namespace, produces no output by itself |
| Variable scope | Shares the caller's existing namespace variables | Keeps definitions isolated in a named namespace object |
| Typical use | Headers, footers, layout fragments | Reusable libraries of macros/functions |
| Access pattern | Nothing to reference afterward - output is already inline | Members accessed as namespace.member |
A useful rule of thumb: reach for #include when you want a fragment's output pasted in place, and #import when you want to call macros or functions defined elsewhere without polluting the current namespace.
More Related questions...