How to call a template which accepts variable number of args in Play Framework 2

前端 未结 3 815
悲&欢浪女
悲&欢浪女 2021-01-12 08:54

The Play Framework 2 template language is pretty nice. However, though it’s ‘inspired by’ Microsoft’s Razor language, one important design decision is different: how you ‘es

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-12 09:30

    Here is a workaround:

    @import views.Common.section
    
    @sec1 = { 

    Blah

    } @sec2 = {

    Blah blah

    } @structuredpage("Dashboard")( section("Latest Requests")(sec1), section("Your Details")(sec2) )

    previous attempt:

    I think your wish makes it to complicated. Templates should be simple. Here is a simple alternative:

    index.scala.html

    @structuredpage("Dashboard"){
        @section("Latest Requests") {
            

    Blah

    } @section("Your Details") {

    Blah blah

    } }

    section.scala.html

    @(title: String)(content: Html)
    
    

    @title

    @content

    structuredpage.scala.html

    @(title: String)(sections: Html)
    
    @main(title){
        
        @sections
    }
    

    I made a gist: https://gist.github.com/4280577 . So you can check it out and play with it.

提交回复
热议问题