In Kohana (PHP framework) the layout is implemented through Template_Controller which continas a member variable called $template, which serves as layout view. Then in the action method you can populate the $template with further sub-views, usually the content view. (http://forum.kohanaframework.org/discussion/3612/kohana-layout-system/p1)
This allows me to change the layout "theme" in the runtime. It is useful for multitenant system, where a tenant can select their own theme (two col, three col, etc.)
How can I achieve that in playframework 2 Scala, with Scala template engine? In other words, I'd like to have multiple layout templates in which a tenant can select from. The controller then renders the layout template and the action specific content template.
Something like (Controller's action pseudocode):
- Based on user, retrieve the layout theme (a name stored in string in a database, and has corresponding mapping view file).
- Render the action specific content view.
- Render layout view obtained from (1) along with the (2).
Note: for each action, the layout theme may change per user but the content view remains same.
In it's documentation (http://www.playframework.com/documentation/2.1.1/ScalaTemplateUseCases)
the content template, say, the index.scala.html, includes a call to the main which is defined in main.scala.html, the layout template. In other words, it is hard coded, thus index.scala.html is tightly coupled to main.scala.html.
I though about calling the main from the controller using reflection, and then passing the content.
An alternative would be to use a interpreted template engine such as Scalate.
Any suggestion?