[英]How to render a scalate template manually?
I want to try Scalate in this way:我想以这种方式尝试Scalate :
But I sad found nothing to do this even if I have read all the documentation and source code I found.但是我很伤心,即使我已经阅读了我找到的所有文档和源代码,也没有发现任何事情可以做。
In order to make this question more clear, so I have such a template user.html
:为了让这个问题更清楚,所以我有这样一个模板
user.html
:
<%@ var user: User %>
<p>Hi ${user.name},</p>
#for (i <- 1 to 3)
<p>${i}</p>
#end
<p>See, I can count!</p>
I want to render it with a user instance User(name="Mike")
.我想用用户实例
User(name="Mike")
渲染它。 How to do it?怎么做?
Suppose you have the following simple_example.mustache
template:假设您有以下
simple_example.mustache
模板:
I like {{programming_language}}
The code is {{code_description}}
You can render the template with this code:您可以使用以下代码呈现模板:
import org.fusesource.scalate.TemplateEngine
val sourceDataPath = os.pwd/"simple_example.mustache".toString
val engine = new TemplateEngine
val someAttributes = Map(
"programming_language" -> "Scala",
"code_description" -> "pretty"
)
engine.layout(sourceDataPath, someAttributes)
Here's the result:结果如下:
I like Scala
The code is pretty
Once you get past the initial learning hump, Scalate is actually pretty nice to work with (the docs don't make the lib easy to use).一旦你克服了最初的学习障碍,Scalate 实际上非常好用(文档并没有让 lib 易于使用)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.