Create Scala.html Files In Play 2 Framework
Solution 1:
You don't need to use @helper
or @tags
they are for including templates in other templates, just use common rendering, first create the files:
- app/views/canvas.scala.html
- app/views/edit.scala.html
- app/views/admin.scala.html
So then in your Appliaction
controller create three actions representing each view
publicstatic Result canvas(){
return(views.html.canvas.render());
}
publicstatic Result canvas(){
return(views.html.edit.render());
}
publicstatic Result canvas(){
return(views.html.admin.render());
}
For each action you also need to create a route
in conf/routes
to 'translate' given URL to proper action (first is default):
GET/ controllers.Application.canvas()
GET/edit controllers.Application.edit()
GET/admin controllers.Application.admin()
Finally in each view add that block, to get the 'main menu' displayed on every page. Note: use reverseRouting as a href
of links to make sure they are always correct - even if you change something in routes (de facto, here you could use @tags for including this block from one file to many views, however place it manually now):
<divclass="main-nav"><ahref='@routes.Application.canvas()'>Canvas page</a><ahref='@routes.Application.edit()'>Edit form</a><ahref='@routes.Application.admin()'>Admin area</a></div>
You have now sample for basic application with 3 actions, with separate view
for each.
At the end, don't be angry with me, but you need to spent more time studying official documentation and included Java samples. I showed you basic scenario, which allows you to navigate between three pages and nothing else. Most probably it's not enought to write working app, however describing it makes no sense - as it's described yet in the docs and demonstrated in samples.
Post a Comment for "Create Scala.html Files In Play 2 Framework"