I see 2 options to accomplish what you need. The first would be to pass the theme parameter to your templates (for example, something to tell the called template which theme / layout to use) and use this parameter to conditionally call the layout template. The second way is to process the condition inside the controller by returning the corresponding view based on the selected topic.
Option 1
In your action, you will want to pass some value to your template to indicate which theme to use.
def index = Action { Ok(views.html.index("two-col")) }
Then in your index.scala.html you would do something like this:
@(theme: String) @content = { <h1>Action Specific Content</h1> } @if("two-col" eq theme) { @twoCol("title")(content) } else { @main("title")(content) }
This assumes that there is a twoCol.scala.html template, for example:
@(title: String)(content: Html) <!DOCTYPE html> <html> ... <body> <h1>Two Column</h1> @content </body> </html>
Note. You can also pass the topic using an implicit parameter, see this SO question . This will make it easier to explicitly pass the template for each rendering.
Option 2
It would be as simple as the following in your controller, but would probably require much more repetitive code in presentation templates.
def index = Action { var theme = ... ... if (theme eq 'tow-col') { Ok(views.html.twocol.index("two-col")) } else { Ok(views.html.default.index()) }
It is assumed that the twocol and default package in /app/views has index.scala.html .
Additional comments
As you can tell from option 1, index.scala.html is not closely related to main.scala.html. You can replace the call with the main one with a call to any other template or even without a template.
FWIW, I would go with option 1, and it would probably turn into a better solution.