Created
January 17, 2011 23:58
-
-
Save wfaler/783739 to your computer and use it in GitHub Desktop.
advancedlayoutmodel.scala
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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