如何逃离Rythm的@符号?

时间:2016-01-12 03:36:47

标签: java template-engine rythm

我正在使用Rythm(yup no h),一个Java模板引擎。

想法是替换模板文件中的占位符(例如文本文件)。

就我而言,我正在处理JSON。要调用Rythm引擎,我只需要这样做:

Rythm.render("my @var1 content and my email is joe@acme  (or call @var2)", "foo", "bar");

输出

[DEBUG] org.rythmengine.RythmEngine:69  - Rythm-1.1.1-    SNAPSHOT started in prod mode
my foo content and my email is joebar (or call )
[ INFO] org.rythmengine.RythmEngine:84  - Shutting down Rythm Engine: [re-wZ5]

正如您所看到的,值"bar"转到@acme,引擎误认为是占位符。我怎么能逃脱@符号?

由于

1 个答案:

答案 0 :(得分:1)

您可以将@翻倍以逃避它:

joe@acme => joe@@acme

http://rythmengine.org/doc/template_guide.md#at

的结帐文件

编辑 - 添加示例代码

    System.out.println(Rythm.render("my @var1 content and my email is joe@@acme.com  (or call @var2)", "foo", "bar", "foo", "bar"));

产量

[DEBUG]   org.rythmengine.RythmEngine:69  - Rythm-1.1.1-SNAPSHOT started in prod mode
my foo content and my email is joe@acme.com (or call bar)
[ INFO]   org.rythmengine.RythmEngine:84  - Shutting down Rythm Engine: [re-pI7]