Skip to content

compileVirtual should not depend on File object to template #143

Open

Description

@unoexperto

I think TwirlCompiler.compileVirtual should not depend on File object to template because internally it's used only to generate template name. This prevent clients from compiling twirl templates on the fly. In my case I'd like admins of web-service to be able to update templates via API which are stored in DB.

Activity

  1. mkurz commented on Sep 7, 2017

    @mkurz
    Member

    @unoexperto How about a pull request? 😄

  2. mkurz commented on Dec 4, 2025

    @mkurz
    Member

    +1
    When I was writing compiler tests I had to create a temporary template file, I was wondering why it is not possible to compile a template without having to create a file:

    private val tmpTemplateFile = new File(sourceDir, "temporary.scala.html")

    "using pure code blocks" in {
    TwirlIO.writeStringToFile(
    tmpTemplateFile,
    """@var field = @{ "bar1" }
    |@field = @{ "bar2" }
    |@field""".stripMargin
    )
    val helper = newCompilerHelper
    val compiled = helper.compile[(() => Html)]("temporary.scala.html", "html.temporary")
    compiled.static().toString.trim.replace("\n", "").replaceAll("\\s+", "") must be(
    """bar2"""
    )
    }

    override def afterEach(): Unit = {
    tmpTemplateFile.delete()
    super.afterEach()
    }

  3. mkurz commented on Dec 4, 2025

    @mkurz
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions