Listing and listing in playframework scala templates

I have a header.scala.html file that expects a string and a list parameter

ie @(title: String)(scripts: List[String])

Other scala files will reference the header and will pass specific lists, for example

 @import scala._ @{val jsList = List("a", "b")} @views.html.header("title"){jsList} 

However, I get a Compliance error type mismatch; found: play.api.templates.Html required: java.util.List [String]

There must be some kind of syntax problem that I don't see ... Anyone?

Thanks.

+4
source share
1 answer

You cannot declare variables (for example) in game templates. ( here is a discussion of google groups )

The first thing you can do is that you only need one value in your template:

 @views.html.header("title")(List("a","b")) 

Note that you should use ( and ) , I believe that everything between {} interpreted as HTML code (hence an error of your type of mismatch).

However, this is not suitable if you need it several times in your templates. Then you can use the defining block:

 @defining(List("a","b")) { jsList => @* using it once *@ @views.html.header("title")(jsList) @* using it twice *@ <p>My list contains @jsList.size elements.</p> @* ... *@ } 
+5
source

Source: https://habr.com/ru/post/1484939/


All Articles