include

Synopsis

[#include path]
or
[#include path options]

Where:

  • path: The path of the file to include; must be an expression evaluates to a string
  • options: One or more of these: encoding=encoding, parse=parse
    • encoding: Expression evaluates to string
    • parse: Expression evaluates to boolean (also accepts a few string values for backward compatibility)

Description

This directive is kind of deprecated. That said, we don't plan to remove it, but in almost all use cases you should use the import directive or the embed directive instead.

This directive is the same as the embed directive, except that the included template will use the namespace of the including template. That is, variables (like macros) created in the including template will be visible for the included template, and also the other way around. For example, assume /common/copyright.ftl contains:

Copyright 2001-2002 ${me}<br>
All rights reserved.
[#set justExpreiment = "I'm polluting your namespace!"]  

Then this:

[#set me = "Juila Smith"]
<h1>Some test</h1>
<p>Yeah.
<hr>
[#include "/common/copyright.ftl"]
Also: ${justExpreiment}  

will output this:

<h1>Some test</h1>
<p>Yeah.
<hr>
Copyright 2001-2002 Juila Smith
All rights reserved.
Also: I'm polluting your namespace!  

So here multiple templates are using a common namespace, potentially clobbering the variables of each other. This can easily cause maintenance headaches, so use it only if you are sure you need this feature. If you just want to share common variables and macros with other templates, you should use the import directive.


Page generated: 2008-07-16 22:54:16 GMT FreeMarker Manual -- For FreeMarker 2.4pre1 - INCOMPLETE/OUTDATED!