How to select theme based template in in play 2.5?

140 views Asked by At

I use Play 2.6 for my web application in AWS. I have been using one HTML5+CSS theme for the application so far. However as part of making the theme changeable as per user demands, I need to select and load the theme selected by the user. How can I use a dynamic template in Play - Java Controllers?

public Result index() {
   String theme = "skeleton"; // Will be a user selection finally.
   String workflow = "mainpage"; // this will be different for each page
   return ok(index.render(theme, workflow));
}

For workflow = mainpage, I currently use default theme as follows in mainpage.scala.html

<body>
     @* And here's we render the `Html` object containing
     *  for the the main page content. *@
        @mainpage()
</body>

Is it feasible to select the theme and workflow based scala html template - something like...

@[email protected] 

in the index.scala.html?

Or is there a best practice for dynamic theme selection in Play Framework? When I try the above, I get in html

@[email protected] as output. Basically no content is extracted.

1

There are 1 answers

0
temonehm On

may be you can read this answer

You can switch the template value at the controller or at the views but for me, I think it's better to switch it at the controller and just point out which folder for your view. You can save the selected themes at the file or database and remember to set the default themes.