簡體   English   中英

如果由父模板調用,Rythm無法@import模板

[英]Rythm can't @import a template if invoked by a parent template

我有一組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")行的@import("Helper")遇到錯誤:

Exception in thread "main" org.rythmengine.exception.CompileException: Syntax error on token "import", delete this token

Template: /path/to/templates/Child1.rythm

我嘗試注釋掉@import ,但是后來我不能真正調用那些@def ,並且從Rythm收到錯誤,當我使用@Helper.foo(bunchOfData.getSomething())時,“無法解析幫助​​器”。

為了從Child1和Child2訪問Helper中的這些@def ,我需要做什么?

您不應使用@import ,而應使用@include @import就像java中的import指令一樣,為此模板添加了一個要引用的包。 @include用於添加可以在整個模板中引用的其他模板。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM