So the way the layouts work with the other template languages in
Scalate is you define attributes inside the templates which are then
passed into the layout template as template attributes. However
Mustache has no 'set attribute' syntax since its a 'no logic in the
template' style.
We've had a long standing pending issue to make it easier to do a pure
mustache layout nicely...
http://www.assembla.com/spaces/scalate/tickets/122
I've just added an implementation which provides a way in the layout
template to navigate over the markup of the generated template output
using the element names.
Its probably better if I show you a sample template
https://github.com/scalate/scalate/blob/master/scalate-core/src/test/resources/org/fusesource/scalate/mustache/sample.mustache
Notice the layout navigates the special 'html' section (which
represents the HTML markup of the generated template content) then all
the child sections pull out child elements by name. Also notice that
you can use _ to refer to all the children. Names starting with @
refer to attributes. (This is using the NodeSeq.\(name: String) method
BTW underneath).
So inside the {{#head}} section you can refer to {{title}} and you'll
get the entire <title> element (attributes and all). If you want the
contents of an element, create a section for it and use _ (e.g. the
way we exclude the <body> element in the layout but just use all the
children)
the test case is here with the expected output:
https://github.com/scalate/scalate/blob/master/scalate-core/src/test/scala/org/fusesource/scalate/mustache/LayoutTest.scala#L30
--
James
-------
FuseSource
Email: ja...@fusesource.com
Web: http://fusesource.com
Twitter: jstrachan
Blog: http://macstrac.blogspot.com/
Open Source Integration
Currently the {{#html}} basically means parse the output as XML
markup. To be parsable as XML markup you need a single root element,
so wrapping the whole thing in <html> is a good idea. Though if you
want to omit the <head> and just use title directory thats fine
too....
<html>
<title>My Title!</title>
<body>
Whatever else I <span>need</span>.
</body>
</html>
Though I guess one of the big strengths of Mustache is it can work on
valid HTML docs that can be owned by a designer; so having a <head>
might be nice to do; but not required for sure.
Notice the layout navigates the special 'html' section (which
represents the HTML markup of the generated template content) then all
the child sections pull out child elements by name. Also notice that
you can use _ to refer to all the children. Names starting with @
refer to attributes. (This is using the NodeSeq.\(name: String) method
BTW underneath).