使用 Scala 模板代码块和值作为模板调用的参数(Play Framework)
Using scala template code blocks and values as argument to template call (Play Framework)
我尝试使用可重用代码块和可重用值作为函数调用(另一个模板)的参数,但总是以编译错误告终:"illegal start of simple expression".
假设我有 header
模板,它接受一个字符串作为参数。它是这样称呼的:@header("My title")
现在,我希望 "My title" 成为代码块或值的结果。
比如我试过这样的代码块:
@headerText(workbookArea: WorkbookArea, workbookItemName: String) = @{
workbookArea.className + " > " + workbookItemName
}
@header(@headerText(workbookArea, workbookItemName))
或者这样的值:
@defining(workbookArea.className + " > " + workbookItemName) { headerText =>
@header(@headerText)
}
但是这两个代码片段中的 none 可以编译。应该怎么做?
如果您向我们展示了一个错误,那会更容易 - 不要在括号内使用 @
符号,它应该是:
@header(headerText(workbookArea, workbookItemName))
我尝试使用可重用代码块和可重用值作为函数调用(另一个模板)的参数,但总是以编译错误告终:"illegal start of simple expression".
假设我有 header
模板,它接受一个字符串作为参数。它是这样称呼的:@header("My title")
现在,我希望 "My title" 成为代码块或值的结果。
比如我试过这样的代码块:
@headerText(workbookArea: WorkbookArea, workbookItemName: String) = @{
workbookArea.className + " > " + workbookItemName
}
@header(@headerText(workbookArea, workbookItemName))
或者这样的值:
@defining(workbookArea.className + " > " + workbookItemName) { headerText =>
@header(@headerText)
}
但是这两个代码片段中的 none 可以编译。应该怎么做?
如果您向我们展示了一个错误,那会更容易 - 不要在括号内使用 @
符号,它应该是:
@header(headerText(workbookArea, workbookItemName))