Archive for February, 2015

One issue I came across working with Scala is to do regular for-loops. This is quite easy, here is an example from a !play template I have been working on:
/* The for-loop, with i as indexer variable */
@for(i <- 0 to (subscriptionSerieTypes.length -1)) {

/* Then you can check againts i in the code and output html */
@if(i == 0 || i%3 == 0) {
<div class=”span12″ style=”margin: 0 0 0 10px”>

/* Use (i) to get hold of the current object in the loop */
<div style=”margin:10px 10px 20px 0px”>@subscriptionSerieTypes(i).description</div>



Read Full Post »

I’m using play! framework for Scala in a project and wanted to define a variable in the template (usually this is not required since you will fetch data from the parameters sent to the page), but this is how I did it:

In the template, at the top I did import the class I wanted to use and defined my variable like this (you must set a value otherwise the compiler will give an error):
@import models.SubscriptionSerieType; var myList : Seq[models.SubscriptionSerieType] = null

Then, later in the template I set the variables value like this:
@{myList = subscriptionSerie.subscriptionserietypes.sortWith(_.order < _.order)}

It can then be used in the template, here is a short example (which displayed the length on the sequence):

Read Full Post »