Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如果某个东西没有';是否已包含在FreeMarker中?_Freemarker - Fatal编程技术网

如果某个东西没有';是否已包含在FreeMarker中?

如果某个东西没有';是否已包含在FreeMarker中?,freemarker,Freemarker,PHP有一个函数include_once('target'),这样它就可以包含target,但前提是之前没有包含它。freemarker有这样的东西吗 Include Once通过不必用代码处理依赖项来防止错误。我有一堆shell脚本来安装我正在模板化的应用程序。当我使用scala导入时,我希望能够在模板中声明它对java有依赖关系,但是如果hadoop模板已经包含,那么它已经包含java。无需包含两次java安装脚本。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' />

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

<#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' />