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