Scala/Java template list iteration and concatenation of string
<p>I want to iterate over a list of strings, concatenate them with the suffix/prefix "" and if it's not the last entry of the list append a comma at end.</p>

<p>Wanted Output example: "circle","cube","banana"</p>

<p>My first try is the following snippet:</p>

<pre><code>@listStringifier(list: List[String]) = @{
  if (list != null &amp;&amp; !list.isEmpty) {
   for ((string, index) &lt;- list.zipWithIndex){if(index != list.size-1){"string",}
   else{"string"}
   }
  }
}
</code></pre>

<p>But this function is always empty when I use @listStringifier anywhere.</p>

<p>Logging within the @listStringifier block shows that it is iterating, but not assigning anything.</p>

<p>If I call the for loop directly in the template like this following snippet it works:</p>

<pre><code>@if (list != null &amp;&amp; !list.isEmpty) {
  for ((string, index) &lt;- list.zipWithIndex){if(index != list.size-1){"@string",}
  else{"@string"}
  }
}
</code></pre>

<p>But I dont want to iterate several times so I want to assign the concatenated string to a variable afterwards.</p>

<p>Any help would be appreciated,
thanks in advance</p>