how to get the controller inside of playframework template?
-
21-12-2019 - |
Question
I used playframework2.2:
My template is:
@(topiclink:String, head: String, rate: Int, topicid:Int, summary: String, pic_url:String)
@if(topiclink=="Shoplist"){
<a class="list-group-item" href="@routes.ShoplistController.pagelist(topicid.toString())">
}else {
<a class="list-group-item" href="@routes.PageController.pagelist(topicid.toString())">
}</a>
I want to write more OOP, I mean I want to use the parameter of:
@(topiclink:Controller, head: String, rate: Int, topicid:Int, summary: String, pic_url:String)
and then can directly @topiclink.pagelist(topicid.tostring())
Then I can directly get to the correspond controller pagelist.
Solution
Passing in the controller directly is probably a bad idea - consider having the controller create objects that represent the data (pagelist) you want.
Regardless, whatever you "pass in", it's the controllers job to "pass it in" - remember all these things are parameters. If you really want the controller, then in the controller where you create your page use the this keyword:
views.html.index.myPage(this, otherParam, ...)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow