Skip to content

Added better support for partials #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

agentgt
Copy link

@agentgt agentgt commented Mar 27, 2012

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.

@sps
Copy link
Owner

sps commented Mar 28, 2012

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

@agentgt
Copy link
Author

agentgt commented Mar 28, 2012

Its not the cleanest solution and I didn't have a chance to add more unit tests.

@agentgt
Copy link
Author

agentgt commented Mar 28, 2012

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).

@chrylis
Copy link

chrylis commented Jan 7, 2014

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.

@sps
Copy link
Owner

sps commented Jan 9, 2014

Are you referring to partials support at all or what this patch provides? Partials are already supported.

@agentgt
Copy link
Author

agentgt commented Mar 29, 2014

@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:

  1. Switch out a partial by adding URI query parameters to the view name. This is useful if you have a template and you want to say dynamically change the sidebar inside the controller by pointing to a different partial. That is a level of indirection is provided for the template partials aka partial aliases.
  2. Rudimentary Template inheritance. Instead of putting {{> 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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants