Skip to content

Instantly share code, notes, and snippets.

@wfaler
Created January 17, 2011 23:58
Show Gist options
  • Save wfaler/783739 to your computer and use it in GitHub Desktop.
Save wfaler/783739 to your computer and use it in GitHub Desktop.
advancedlayoutmodel.scala
class ParentLayoutModel extends LayoutModel{
def model(request: Request, viewModel: Map[String, Any], childView: String): Map[String, Any] = {
val map = new HashMap[String, Any]
// lets start by adding the childView so it's guaranteed to appear!
map += "doLayout" -> childView
// lets see if we want to add a tab panel to this layout!
val regex = new Regex("^.*/composable/.*$")
if(regex.pattern.matcher(request.getPath).matches){
// using a raw Scalate Template Engine with absolute URI to get and render the template.
val engine = RenderEngine.getEngine
val stringWriter = new StringWriter
val writer = new PrintWriter(stringWriter)
val responseContext = new DefaultRenderContext("/layouts/tabs.mustache", engine, writer)
responseContext.render("/layouts/tabs.mustache", Map[String, Any]())
map += "tabsPanel" -> stringWriter.toString
}
return map.toMap
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment