Is it possible to prettify scala templates using play framework 2?

后端 未结 5 2076
半阙折子戏
半阙折子戏 2021-01-31 20:10

Using Play Framework 2 I\'ve noticed the rendered Scala HTML templates don\'t like indented @if or @for.

So, for example, something like that:<

5条回答
  •  广开言路
    2021-01-31 20:30

    Echoing on bluenote10's answer I created the following, it does not require third party libraryDependecies. It would be nice to integrate it into a filter, unfortunately I am not sure how to do that correctly today.

    import play.twirl.api.Html
    
    /** Helper to format Html */
    def prettify(content: Html): Html = {
      Html(content.body.trim().replaceAll("\\n\\s*\\n", "\n"))
    }
    
    def index = Action { implicit request =>
      Ok(prettify(views.html.index()))
    }
    

提交回复
热议问题