playframework / twirl

Twirl is Play's default template engine
Apache License 2.0
545 stars 108 forks source link

Any way to have twirl work with css files? #369

Closed fancellu closed 3 years ago

fancellu commented 4 years ago

e.g.

blah.scala.css

so we can use the power of twirl/scala to generate our css

Like a suped up SASS

I see the docs say it only supports js/html/txt/xml

fancellu commented 4 years ago

Ok, to answer my own question


def css = Action {
    val css: TxtFormat.Appendable =views.txt.css()
    Ok(css).as("text/css")
  }

inside HTML

  <link rel="stylesheet" href="@routes.HomeController.css()"/>

inside css.scala.txt, the css. with @ escaped to @@ (twirl likes @)

ignasi35 commented 3 years ago

This sounds solved. I'll close it.

Thanks, @fancellu for coming back and take the time to leave an answer. :-)