If you use Maven for building your project, add following lines to pom.xml
(or merge XML sections accordingly):
<properties>
<cx.version><!-- desired version --></cx.version>
</properties>
<dependencies>
<dependency>
<groupId>ru.circumflex</groupId>
<artifactId>circumflex-ftl</artifactId>
<version>${cx.version}</version>
</dependency>
</dependencies>
If you prefer SBT, make sure that libraryDependencies
of your project contains following artifact:
"ru.circumflex" % "circumflex-ftl" % cxVersion % "compile->default"
where cxVersion
points to desired Circumflex version. Here's the sample project configuration:
import sbt._
class MyProject(info: ProjectInfo) extends DefaultProject(info) {
val cxVersion = "2.0"
override def libraryDependencies = Set(
"ru.circumflex" % "circumflex-ftl" % cxVersion % "compile->default"
) ++ super.libraryDependencies
}
You can follow SBT Setup Guide to create a new project.
Note that first-time builds usually require a substantial amount of dependencies downloads.
You should import this package to use Circumflex FreeMarker Helper in your application:
import ru.circumflex.freemarker._
FreeMarker Helper can be used in several ways:
you can render a response for web application (current instance of CircumflexContext
is passed as data model if none second argument given):
ftl("index.ftl")
you can render a template into String
:
ftl2string("index.ftl")
you can create your own FreeMarker configuration using ScalaObjectWrapper
and use native methods of FreeMarker:
package com.myapp
object MyConfig extends Configuration { {.scala}
setObjectWrapper(new ScalaObjectWrapper())
setTemplateLoader( ... )
setSharedVariable( ... )
}
MyConfig.getTemplate("index.ftl").process( ... )
ru.circumflex.freemarker
package: just set freemarker.configuration
configuration parameter to fully-qualified class name of your configuration implementation (com.myapp.MyConfig$
in our previous example).