acsellers/revel — pull request #1 by acsellers (2013-09-29 00:50:16+00:00)
Title: An implementation of Layouts for html/template

Create a yield function that can output a pre-compiled template by name.
There are two forms of the yield call, a default yield and a named
yield. A default yield takes the form of `yield .` and will output the
template for the current action. There are also named yields that are
set using a ContentFor function within the controller. these take the
form of `yield "header" .` where it will either render an empty string
when ContentFor was not called for the header name, or the template that
was requested by the ContentFor call. An example ContentFor call would
be `c.ContentFor("header", "sessions/logged_in_user.html")`.

To take advantage of the new yield function is the ability to define
layouts that will be rendered. Layouts are rendered after the action
specific template. If layouts are not used, the code will default to the
existing behavior of rendering templates, but if there is an app/layouts
folder or a different folder set in the LayoutPath variable, or multiple
layout paths set in the LayoutPaths variable after initialization by
applications, the developer can define a layout to be rendered.
Default layouts can be set by format, for example,
`revel.DefaultLayout["html"] = "application.html"`. It is expected that
the layout will have a function call like `{{yield .}}` to render the
action's template at some point. By default, this implementation will
look for layouts in an app/layouts folder.

Current known issues with this implementation are:
* If a template that is meant to be a named yield panics from within the
ContentFor call, the panic is not correctly handled. Could be fixed by
changing RenderTmpl from map[string]template.HTML to
map[string]GoTemplate and then rendering the named yields when
rendering the template and layout.
* There is no way to set named yield template from templates in the
manner of RenderArgs yet
* Layouts cannot use {{template "subtemplate.html" .}}
templates in their same folder, must use
{{template "Layout::subtemplate.html .}} instead unless the user
put their layouts within their ViewsPath and set the LayoutPath
variable to be ViewsPath + "/layouts" in which case they should be
able to use {{template "layouts/subtemplate.html" .}}.