Open agentgt opened 12 years ago
Hi Adam,
Thanks for this pull request - I haven't had a chance to review it yet, but I should in the next few days.
Thanks! -sean
Its not the cleanest solution and I didn't have a chance to add more unit tests.
I also noticed that I forgot to use spaces instead of tabs. I used tabs because SpringSource used to use tabs (I'm not sure if they still do).
Will there be any progress on the partials? I'm looking at using a prepackaged template library that's heavily built around a (very nice and clean) partial system, and I'm up for working on the view code as long as it doesn't get too esoteric.
Are you referring to partials support at all or what this patch provides? Partials are already supported.
@chrylis and @sps this patch is to enhance partial support and to add rudimentary layout support. I have mostly switched to Handlebars.java which has its own way of doing layout but we still use Mustache here and there.
There are two things this patch does:
{{> header}}
and {{> footer}}
all over the place the template will be wrapped with a parent layout template. The code does this by walking up the directory structure looking for templates name layout
(configurable).Here is an example of the template inheritance:
Say we have the views:
/WEB-INF/views/layout.mustache
/WEB-INF/views/legal.mustache
/WEB-INF/views/a.mustache
/WEB-INF/views/sub1/b.mustache
/WEB-INF/views/sub1/layout.mustache
/WEB-INF/views/sub2/c.mustache
/WEB-INF/views/layout.mustache
might look something like:
... header stuff...
{{> inner}}
... footer stuff...
{{> legal }}
a.mustache
will be put into /WEB-INF/views/layout.mustache
{{> inner}}
if your controller returns "a
". That is it will be wrapped.
b.mustache
will use /WEB-INF/views/sub1/layout.mustache
where as c.mustache
will use /WEB-INF/views/layout.mustache
(up the tree).
Of course if you don't want c.mustache
to be wrapped then you can use the partial alias support mentioned earlier by doing:
return "sub2/c?layout="
Or maybe you just want to replace legal
partial from /WEB-INF/views/layout.mustache
return "sub2/c?legal=sub2/someother-legal"
I added how it works in the README.MD
I'm using a different version in production but this should work. The partial alias support I added is particularly useful for layout.