General Questions
General questions on the scalate project.
Why the name Scalate?
Scalate stands for Scala Template Engine hence ScalaTE, though its easier on the eye to just write ‘Scalate’
Why should I use Scalate?
Details of why you should use Scalate here
Which template engine should I use?
See which template engine you should use
What is the license?
The license is Apache 2 License
How do I get started?
Try the Getting Started Guide which should have you scalating nicely really quickly!
How do I get support?
See the support guide for more details.
How do I build Scalate?
First get the source then see the building guide
Why does the Maven build not download jars?
The default profile in maven does not include remote repos, so make sure you add the download profile when building for the first time. First get the source then see the building guide.
e.g.
mvn install -Pdownload
Why does the SBT build not find any dependent jars?
We currently support both a Maven and SBT build. We tend to use Maven for doing signed releases and reporting and SBT for incremental compiling and testing when in development.
If you want to just use SBT then you first need to perform a maven build to download all the dependencies
mvn install -Pdownload
The SBT build then uses the dependencies downloaded in your local maven repository. This saves us having to maintain duplicate information for dependency versions and repositories across both builds; the SBT build just reuses the dependencies and repositories from Maven. One day it would be nice for SBT to just be able to parse the pom.xml and find that information for itself, so folks won’t have to do a Maven build first.
For more detail see the building guide.
How do I contribute or become a committer?
We love contributions! More details on how to contribute and how to become a committer are in the contributing guide.
How do I register for the issue tracker?
For more detail see the support page. If you haven’t done so already you can register with the issue tracker here
How does the website work?
For details on how to edit the website and how it works see How the Site works
The Scalate Approach
Should I use SSP or Scaml?
If you know Velocity, JSP or Erb then you will feel right at home with SSP which has very similar syntax - the main difference is its use of Scala for expressions.
However if you are generating markup, particularly HTML, then we highly recommend you take a look at Scaml which is a Scala dialect of Haml. Scaml is a little bit of an acquired taste - if you’ve never used HAML before it might seem a little odd at first; but when you get used to it we’re sure you’ll really like it.
While SSP and Scaml offer the same kinds of features and expressive power, using Scala expressions, iteration, navigation and pattern matching, Scaml really shines for generating HTML and XML markup - its much more concise and DRY. SSP is much better for generating arbitrary textual output such as emails (as Scaml is highly optimised to nested markup and HTML in particular) - or for getting you up to speed quickly on Scalate if you’ve only used JSP or Erb in the past.
How does Scalate compare to JSP?
See our comparison of Scalate to JSP
How does Scalate compare to Lift views?
We compare approaches here, see which is right for you and your team.
Isn’t putting code in views a bad thing?
Well it all depends really; see this article for a more in depth debate on the subject.
Using Scalate
How do I get started?
Your best bet is starting with the User Guide maybe starting by running the samples then for more detail reading either of the template references
How can I use Scalate and Scala in a RAD way?
Scalate itself auto-recompiles and reloads templates on the fly. However if you are changing Scala code which the Scalate templates use then you normally have to stop and restart your web container.
So for a more RAD approach we recommend using JRebel which can hot-reload the Scala code on the fly, leading to a rapid edit <-> browser reload cycle.
How can I access the Servlet request, response or servletContext
When using Scalate with servlets or Jog you might wish to access the current request, response, servletContext or servletConfig objects used by the servlet engine. These variables are all available by default thanks to the ServletRenderContext API which is imported by default.
So your template can refer to these variables if they are required directly - rather like they can be in JSP.
<h1>Hello ${someMethod(request, response)}</h1>
where someMethod is a function takes a Servlet request and response parameter.
However if you are using 1.1 or later you can avoid having to mention these variables in your templates; instead your snippet functions can refer to these values directly (or you can write snippet functions that hide these parameters to simplify your templates)
Can I use Scalate with a non file based template?
You can configure the TemplateEngine to provide a resourceLoader to resolve URIs for templates. See the Custom Template Loading in the Embedding Guide.
Or if you are using the Scalate API directly there are methods on TemplateEngine API for loading a Template by supplying the source of the template as a String. So you can create the template content however you wish, then compile and render the template.
For example
// a template with an attribute
val source = "<%@ val name: String %> hello ${name}"
val template = engine.compileSsp(source)
val output = engine.layout(template, Map("name" -> "James"))
// test it works...
expect("hello James") {output}
Or you can use the TemplateSource companion object helper methods…
// can use fromString, fromUri etc
val source = TemplateSource.fromFile("foo.ssp")
val output = engine.layout(source, Map("name" -> "James"))
To see more examples try the TemplateEngineTest.scala test case
How can I precompile my templates
See the section on precompiling templates in the user guide