template : can't get string in loop

16 views
Skip to first unread message

Roohix

unread,
Oct 7, 2015, 9:42:28 AM10/7/15
to play-framework
I have a wired problem with template ,
when I define loop in two bracket I can't get string and html tag 
play 2.3.x

(I have to use loop in brackets : @{loop} )

@main()) {
    hello
    @{
        var a = 0
        for(a <- 1 to 10) {
           
                <a href="http://blahblah">URL</a>
        }   
    }
}

Output :
hello

luiza...@gmail.com

unread,
Oct 7, 2015, 9:54:36 AM10/7/15
to play-fr...@googlegroups.com
I think a way to do what you want is the following:

@main() {
   @for(a <- 1 to 10) {
        <a href="http://blahblah">URL</a> 
   }
}

Luiz Fernando Alvino

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/play-framework/2a6b4609-19ce-4624-bcd1-cf557e3f79e1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Roohix

unread,
Oct 7, 2015, 10:03:45 AM10/7/15
to play-framework

as i mentioned I have to use loop in brackets : @{loop} 

luiza...@gmail.com

unread,
Oct 7, 2015, 11:27:48 AM10/7/15
to play-fr...@googlegroups.com
The code inside brackets are not play template code but Scala code. If you want to print something from this block, you need to return some value. Something like this:

@main() {
    hello
    @{
        var a = 0
        var s = ""
        for(a <- 1 to 10) {
           s += "<a href=\"http://blahblah\">URL</a><br/>"
        }
        Html(s)
    }
}



Luiz Fernando Alvino

--
You received this message because you are subscribed to the Google Groups "play-framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to play-framewor...@googlegroups.com.

Roohix

unread,
Oct 7, 2015, 12:31:31 PM10/7/15
to play-framework
Thank you


On Wednesday, October 7, 2015 at 6:12:28 PM UTC+4:30, Roohix wrote:
Reply all
Reply to author
Forward
0 new messages