twirl - How to specify that a parameter is optional -
twirl - How to specify that a parameter is optional -
i new twirl, , trying create todo application play, way have right now, trying send 2 objects(an arraylist, , string). have wrapped code in controller in seek catch. if exception caught template should rendered string, not arraylist, , if no exception caught, homecoming arraylist, not string. have tried passing 1 null, sense there improve way it. there? here twirl:
@(message: string, tasks: arraylist[task]) <!doctype html> <html> <head> <title>todo</title> </head> <body> <h1>todos</h1> <p>@message</p> @for(task <- tasks) { <li><@task.task</li> } </body> </html>
you utilize options:
@(maybemessage: option[string], maybetasks: option[seq[task]]) <!doctype html> <html> <head> <title>todo</title> </head> <body> <h1>todos</h1> @for(message <- maybemessage) { <p>@message</p> } @for(tasks <- maybetasks) { @for(task <- tasks) { <li>@task.task</li> } } </body> </html> and controller:
ok(views.html.foo(none, some(seq(task("task 1"), task("task 2"))))) ok(views.html.foo(some("something went wrong."), none)) twirl
Comments
Post a Comment