varag HTML content in Scala Play 2.5 template

18 views
Skip to first unread message

Nathan Coleman

unread,
Dec 1, 2016, 2:21:23 AM12/1/16
to Play Framework
I'm trying to figure out how to have html content passed into a template from another template as a vararg in Scala with Play 2.5.

So for example, I have a template defined with this at the top:
@(foo: String)(content: Html*)(implicit bar: Bar)

I'm able to invoke it in another template with
@template("fooString")(Html("123"), Html("abc"))

Which works, but doesn't escape strings I want to use in the html.
I'm trying to find something that works with the curly-brace syntax, like
@template("fooString"){"123"}{abc}

But I haven't found any permutations of that syntax that have worked. I asked this question on Stack Overflow, but haven't gotten any responses: http://stackoverflow.com/questions/40810861/scala-play-template-vararg-htmlcontent , and someone from work recommended I ask the question here. Does anyone know how I should go about this? Thanks in advance!

Will Sargent

unread,
Dec 6, 2016, 12:36:26 PM12/6/16
to play-fr...@googlegroups.com
The varargs casting syntax is :_* so

@(listOfString: Seq[String])

@functionThatTakesVarArgs(listOfString: _*)

I agree, it's odd.

--
Will Sargent
Engineer, Lightbend, Inc.


--
You received this message because you are subscribed to the Google Groups "Play Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framework+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/585206bd-ce6b-4b97-ad9c-48d4e11b5f33%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Will Sargent

unread,
Dec 6, 2016, 12:54:05 PM12/6/16
to play-fr...@googlegroups.com
Also, there is no curly brace syntax in the way you describe, because technically you're calling a method with multiple parameter lists, and the number of parameter lists is fixed.


It's an interesting idea, and you could probably fake something using snippets...


--
Will Sargent
Engineer, Lightbend, Inc.


Reply all
Reply to author
Forward
0 new messages