我有一组4个模板文件,所有的扩展名都是.rythm,并且都在同一个目录中。我们称它们为"Main.rythm“、"Child1.rythm”、"Child2.rythm“和"Helper.rythm”。此外,在呈现Main之前,我还将home.template.dir设置为该目录。
在Helper模板中,我只有一堆@def,它们执行一些基本的通用格式化,这样我就不必回调我的java类,或者用不需要的逻辑来打乱实际的模板。
Main看起来像这样:
@args {
String aString,
MyClass bunchOfData,
String anotherString
@//...
}
@import("Helper")
There's some formatting here, using @aString
There's some formatting using an @def in Helper, like @foo(anotherString)
@Child1(bunchOfData)
@Child2(bunchOfData)Child1和Child2彼此相似,看起来像这样:
@args MyClass bunchOfData
@import("Helper")
@{
//Some preformatting stuff here
}
Make a lot of method calls on @bunchOfData, some of which will also use an @def or two in Helper我的问题是我在@import("Helper")行的Child1中得到了一个错误:
Exception in thread "main" org.rythmengine.exception.CompileException: Syntax error on token "import", delete this token
Template: /path/to/templates/Child1.rythm我试着注释掉@import,但是我不能真的调用那些@defs,并且在我使用@Helper.foo(bunchOfData.getSomething())时从Rythm得到"Helper out be resolved“的错误。
要从Child1和Child2访问助手中的这些@def,我需要做什么?
发布于 2017-08-25 01:19:29
你不应该使用@import,而应该使用@include。@import就像java中的import指令,为这个模板添加了一个引用的包。@include用于添加附加模板,您可以在整个模板中引用这些模板。
https://stackoverflow.com/questions/45867429
复制相似问题