playframework - Recursive blocks in Scala Play Framework templates -
i'm writing template blog post, has threaded comments. natural way of writing template threaded comments use recursive way constructing html. this:
@showcomment(comment: models.comment) = { <div class="comment"> <div class="comment-metadata"> <span class="comment-author">by @comment.author,</span> <span class="comment-date"> @comment.postedat.format("dd mmm yy") </span> </div> <div class="comment-content"> <div class="about">detail: </div> @html(comment.content.replace("\n", "<br>")) </div> <a href="@action(controllers.application.replycomment(comment.id()))">reply</a> @comments filter { c => c.parent_id == comment.id } map { c => @showcomment(c) } </div> }
the problem using recursive block yields error:
error raised : recursive method showcomment needs result type
if try put return type in showcomment raises errror:
error raised : not found: value showcomment
any workaround?
this works me:
enclose code in @{}
@{ //use regular scala here: def showcomment(comment: models.comment):node = { .... } //the above declared recursive method, call it: showcomment(...) }
- define recursive method
- call method @ end of block
- profit !
Comments
Post a Comment