- General Questions
- Why the name Scalate?
- Why should I use Scalate?
- Which template engine should I use?
- What is the license?
- How do I get support?
- How do I build Scalate?
- Why does the Maven build not download jars?
- Why does the SBT build not find any dependent jars?
- How do I contribute or become a committer?
- How do I register for the issue tracker?
- How does the website work?
- The Scalate Approach
- Using Scalate
- How do I get started?
- How do I enable or disable markup escaping
- How do I disable layouts?
- How can I use Scalate and Scala in a RAD way?
- How can I access the Servlet request, response or servletContext
- Can I use Scalate with a non file based template?
- How can I precompile my templates
- How can I change the default layout templates
- Is there a Scalate version of custom tag libraries
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 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
Which template language should I use?
See the how to choose which template language
Is putting code in views a bad thing?
Well it all depends really; see this article for a more in depth debate on the subject.
If you don't like to put any code in a view then maybe start with the mustache template language.
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.
Using Scalate
How do I get started?
Try the Getting Started Guide which should have you scalating nicely really quickly!
How do I enable or disable markup escaping
By default Scalate will safely escape any markup characters to avoid you creating invalid or unsafe markup.
However sometimes you want to output a Scala expression which is a String but contains markup you wish to preserve and not escape.
Firstly escaping is enabled by default via the escapeMarkup property on TemplateEngine; as you create a RenderContext it inherits the setting. So you can globally disable escaping by just setting the flag on the TemplateEngine.
Or you can enable/disable it inside a template.
<% escapeMarkup = false %>
The other option is to wrap your expression inside the escape or unescape methods.
e.g.
some text
${unescape("<h1>hello there</h1>")}
Incidentally we assume NodeSeq from Scala's XML API is already markup so we don't escape it. So if you have an expression which is a NodeSeq then it won't be escaped.
<% val markup = <h1>hello<h1> %>
<% val text = "<h1>hello<h1>" %>
this will not be escaped ${markup}
this will be escaped ${text}
How do I disable layouts?
If you want to disable layouts, just set the layoutStrategy property on the TemplateEngine to be the NullLayoutStrategy
Or you can just create an empty layout. For example if you are using servlets or JAXRS, just create a template in /WEB-INF/scalate/layouts/default.ssp which just includes the body and does not perform any actual layout.
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
How can I change the default layout templates
The list of default layout templates is a constructor parameter in the DefaultLayoutStrategy class; its configured by default in the ServletTemplateEngine.setLayoutStrategy(templateEngine) method.
Though you can just specify whatever defaults you wish if you are using some framework to configure the TemplateEngine instance (whether using a regular TemplateEngine or the ServletTemplateEngine)
val engine = new ServletTemplateEngine
engine.layoutStrategy = new DefaultLayoutStrategy(engine,
"something.ssp", "whatnot/somethingElse.jade")
The other option is to define the layout attribute to be whatever layout template you wish before rendering your template.
Is there a Scalate version of custom tag libraries
In template engines like JSP and GSP its common to use XML tag libraries. Its a pending support request which we might implement in SSP one of these days.
Though typically its easier to just use a Scala method call in Scalate rather than mapping namespaced XML elements to functions.
Refer to the user guide on calling functions and passing blocks for some samples. An example of this kind of thing is performing a layout of a template block