I want to try Scalate in this way:
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
:
<%@ 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")
. How to do it?
Suppose you have the following simple_example.mustache
template:
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With