Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop over java Map with scalate's mustache implementation

Can mustache loop over a java Map? My object:

Map<Integer, String> mapTest

Tried this in my mustache template:

{{#mapTest}}
  {{.}}
{{/mapTest}}

That spits out a string representation (mapTest.toString()) of the entire object but doesn't loop at all.


Update: In hunting through the source I'm getting closer but still not sure how to do it. https://github.com/scalate/scalate/blob/ec981338c067fcf37106fb5f3bdf2fa8c4e458ca/scalate-core/src/main/scala/org/fusesource/scalate/mustache/Scope.scala#L124-125

like image 937
devth Avatar asked Dec 06 '25 16:12

devth


2 Answers

See this answer on the mailing list...

http://groups.google.com/group/scalate/msg/100df004001d84f0

like image 133
James Strachan Avatar answered Dec 08 '25 08:12

James Strachan


You could convert the Java Map to a Scala Map.

import scala.collection.JavaConverters._
val myScalaMap = myJavaMap.asScala.mapValues(_.asScala.toSet)

I wouldn't hack the template to accommodate a Java object.

like image 27
Powers Avatar answered Dec 08 '25 06:12

Powers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!