Search code examples
sbtplaybackscala.jstwirl

call twirl template from ScalaJs


The play framework documentation says (https://www.playframework.com/documentation/2.6.x/ScalaTemplates): You can then call this from any Scala code as you would normally call a method on a class:

val content = views.html.Application.index(c, o)

Is there an easy way to call twirl templates within ScalaJs for a crossProject(JSPlatform, JVMPlatform).crossType(CrossType.Pure)


Solution

  • Given that Twirl, the templating framework of Play, supports Scala.js, it should relatively simple. The only thing is that, by default, Twirl will not look for templates in the shared source directory. So you'll need to configure its source directories, as explained in its readme, using something like:

    sourceDirectories in (Compile, TwirlKeys.compileTemplates) +=
      baseDirectory.value.getParentFile / "src/main/twirl"