Popularity
7.0
Growing
Activity
8.8
-
536
37
109

Programming language: Scala
License: Apache License 2.0
Tags: Templating    
Latest version: v1.5.0

Twirl alternatives and similar packages

Based on the "Templating" category.
Alternatively, view Twirl alternatives based on common mentions on social networks and blogs.

  • Scalate

    Scalate is a Scala based template engine which supports HAML, Mustache and JSP, Erb and Velocity style syntaxes.
  • Beard

    A lightweight, logicless templating engine, written in Scala and inspired by Mustache

Do you think we are missing an alternative of Twirl or a related project?

Add another 'Templating' Package

README

Twirl

Twitter Follow Discord GitHub Discussions StackOverflow YouTube Twitch Status OpenCollective

Build Status Maven Repository size Scala Steward badge Mergify Status

Twirl is the Play template engine.

Twirl is automatically available in Play projects and can also be used stand-alone without any dependency on Play.

See the Play documentation for the template engine for more information about the template syntax.

sbt-twirl

Twirl can also be used outside of Play. An sbt plugin is provided for easy integration with Scala or Java projects.

sbt-twirl requires sbt 1.3.0 or higher.

To add the sbt plugin to your project add the sbt plugin dependency in project/plugins.sbt:

// twirl 1.6 and newer:
addSbtPlugin("com.typesafe.play" % "sbt-twirl" % "LATEST_VERSION")
// twirl 1.5 and before:
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")

Replacing the LATEST_VERSION with the latest version published, which should be Latest version. And enable the plugin on projects using:

someProject.enablePlugins(SbtTwirl)

If you only have a single project and are using a build.sbt file, create a root project and enable the twirl plugin like this:

lazy val root = (project in file(".")).enablePlugins(SbtTwirl)

Template files

Twirl template files are expected to be placed under src/main/twirl or src/test/twirl, similar to scala or java sources. The source locations for template files can be configured.

Template files must be named {name}.scala.{ext} where ext can be html, js, xml, or txt.

The Twirl template compiler is automatically added as a source generator for both the main/compile and test configurations. When you run compile or Test/compile the Twirl compiler will generate Scala source files from the templates and then these Scala sources will be compiled along with the rest of your project.

Additional imports

To add additional imports for the Scala code in template files, use the templateImports key. For example:

TwirlKeys.templateImports += "org.example._"

Source directories

To configure the source directories where template files will be found, use the compileTemplates / sourceDirectories key. For example, to have template sources alongside Scala or Java source files:

Compile / TwirlKeys.compileTemplates / sourceDirectories := (Compile / unmanagedSourceDirectories).value

Releasing a new version

See https://github.com/playframework/.github/blob/main/RELEASING.md

Credits

The name twirl was thought up by the Spray team and refers to the magic @ character in the template language, which is sometimes called "twirl".

The first stand-alone version of Twirl was created by the Spray team.

An optimized version of the Twirl parser was contributed by the Scala IDE team.