使用Rythm模板引擎过滤代码

时间:2015-06-21 08:55:39

标签: java rythm

是否可以在Rythm中过滤代码?

我希望允许使用iffor等特定代码,同时拒绝所有其他代码(尤其是@{ })。

1 个答案:

答案 0 :(得分:0)

目前没有过滤机制。但是,Rythm提供了一个名为Dialect的实用程序,允许模板作者使用Rythm指令的限制集。例如,SimpleRythm不允许您使用以下指令:

"@extends",
"@section",
"@render",
"@inherited",
"@doLayout",
"@doBody",
"@include",
"@set",
"@get",
"@init",
"@finally",
"@nosim"

虽然BasicRythm受到更多限制,但您不允许使用以下任何指令:

"@args",
"@assign",
"@debug",
"@doLayout",
"@doBody",
"@extends",
"@section",
"@render",
"@inherited",
"@i18n",
"@import",
"@include",
"@invoke",
"@locale",
"@set",
"@get",
"@init",
"@finally",
"@expand",
"@exec",
"@macro",
"@compact",
"@nocompact",
"@def ",
"@tag ",
"@return",
"@nosim",
"@verbatim"

为了使用特定的方言,而不是使用

String result = engine.render(...);

使用以下代码:

ITemplate template = engine.getTemplate(SimpleRythm.INSTANCE, ...);
String result = template.render();

暂时无法阻止@{...}。请在https://github.com/greenlaw110/rythm/issues上提交票证以请求配置以禁用Rythm模板中的脚本