I've been using the--quite excellent--playframework and have had trouble finding documentation/examples on how to access a Map data structure from a view, using play's template engine.
To be even more specific, I wish to access the Map as I iterate over a List of objects, e.g.,
#{list items:itemList, as:'item'}
// access the map value using the ${item?.id} as the key
#{/list}
Thank's for looking.
This is a generic solution to iterate on Map in using Play! Framework:
in the controller :
render(map);
in the template:
#{list items:map.keySet(), as:'key'}
${map.get(key)}
#{/list}
The fact that you want to rely on a side List to iterate on your Map suggest me that you are searching a predictible way for your iteration process.
In that case, just remember that iteration will be unpredictable if you don't use an ordered/sorted Map implementation.
Assuming you do in the Controller:
render(map, itemList); //map is a Map
This should work:
#{list items:itemList, as:'item'}
// access the map value using the ${item?.id} as the key
${map.get(item.?id)}
#{/list}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With