Declare variable in a Play2 scala template

前端 未结 8 1562
谎友^
谎友^ 2020-11-27 17:33

How do you declare and initialize a variable to be used locally in a Play2 Scala template?

I have this:

@var title : String = \"Home\"
8条回答
  •  無奈伤痛
    2020-11-27 18:29

    In twirl templates I would recommend using the defining block, because the

    @random = @{
         new Random().nextInt
    }
    
    

    would result in different values when used multiple times!

    @defining(new Random().nextInt){ random =>
        
    }

提交回复
热议问题