Skip to content

StringInterpolation not works well with Seq #347

@clouds56

Description

@clouds56
import play.twirl.api.StringInterpolation
val test_seq = Seq(10,20,30)
def test_div(i: Int) = html"<div>$i</div>"
html"""
<ul>
  <li>${test_div(-1)}</li>
  ${test_seq.map(i => <li>{test_div(i)}</li>)}
</ul>
"""

outputs

<ul>
  <li><div>-1</div></li>
  <li>&lt;div&gt;10&lt;/div&gt;</li><li>&lt;div&gt;20&lt;/div&gt;</li><li>&lt;div&gt;30&lt;/div&gt;</li>
</ul>

While I expects

<ul>
  <li><div>-1</div></li>
  <li><div>10</div></li><li><div>20</div></li><li><div>30</div></li>
</ul>

I know I can do this using

val test_seq = Seq(10,20,30)
def test_div(i: Int) = html"<div>$i</div>"
html"""
<ul>
  <li>${test_div(-1)}</li>
  ${test_seq.map(i => html"<li>${test_div(i)}</li>")}
</ul>
"""

but I hope we could have it done without nested quoting

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions