我如何仅包含尚未包含在 FreeMarker 中的内容?

How do I include something only if it hasn't already been included in FreeMarker?

PHP 有一个函数 include_once('target') 这样它将包含 target 但前提是它之前没有被包含。 freemarker 有这样的东西吗?

Include Once 不必用代码处理依赖关系,从而防止错误。我有一堆 shell 脚本来安装我正在模板化的应用程序。当我使用 scala 导入时,并希望能够在模板中声明它依赖于 java,但是如果 hadoop 模板已经包含,那么它已经包含 java。无需两次包含 java 安装脚本。 freemarker 可以做到吗?

没有内置这样的指令,但可以用宏来模拟,只要你至少不使用相对路径:

<#global incuded = {}>

<#macro includeOnce path>
  <#if !path?startsWith('/')>
    <#stop "The path must start with /">
  </#if>
  <#if incuded[path]??><#return></#if>
  <#include path>
  <#global incuded += {path: true}>
</#macro>

然后:

<@includeOnce '/something.foo' />