[Play 2.4] View of module with injected layout

16 views
Skip to first unread message

Hubert Świetlicki

unread,
Oct 2, 2015, 9:15:55 AM10/2/15
to play-framework
Hi!

I start working with Guice and new Play 2.4 DI and there is something I am missing.

I am working on my own Auth Module for Play 2.4, which is supposed to be used by many applications. Right now, I have the following folder structure for my core module:

|-- core
    |-- controllers
        |-- LoginController.scala
    |-- models
        |-- SessionService.scala
        |-- SessionServiceModule.scala
    |-- views
        |-- Login.scala.html
|-- config
    |-- core.routes

I prepared the authentication part which can store session data in play Cache, the module is created and wired up.
From my application project, I can access core.routes (via '-> /core core.Routes' syntax), the LoginController.scala can render part of page with login form.

The question: how should I proceed in order to pass the layout view for my Login.scala.html? Right now the Controller looks like this: 

package core.controllers

import core.models.session.LoginData
import play.api.mvc.{Action, Controller}
import play.api.data._
import play.api.data.Forms._

class LoginController extends Controller {

    val loginForm
= Form(
    mapping
(
     
"login" -> nonEmptyText,
     
"password" -> text,
     
"newPassword" -> text
   
)(LoginData.apply)(LoginData.unapply)
 
)

 
def loginFormAction = Action { implicit request =>
   
Ok(core.views.html.Login(loginForm))
 
}
}


and the Login.scala.html view:
@(loginForm: Form[core.models.session.LoginData], hasError: Boolean = false)

<div class="panel-body">
 
@helper.form(action = core.controllers.routes.LoginController.loginAction(), 'class -> "form form-horizontal") {
    ///... inputs, buttons etc.
  }
</div>


I wish for this view to be only a part of a bigger picture (i.e. it should be packed in HTML tag, get the HEAD section, scripts etc.), which would be passed (injected) from the application down to the module.
Best regards,

Hubert
Reply all
Reply to author
Forward
0 new messages