Partials are getting more powerful in the 1.0 release. There are two main problems we want to solve with how partials are compiled into a view. The first problem we're solving is purely organizational. Most Pakyow apps have several partials in the root view directory that are used throughout the app. Here's an example view structure:
index.html documents could include the
foo partial with the following directive:
<!-- @include foo -->
If we want to override the partial for
resource, we could do that by defining a
While this will still work in 1.0, best practice will place
_foo.html in the
app/presentation/partials directory (see the Code Loading & Organization discussion for more on the new structure). Nothing will change as to how these shared partials are used, they'll just have a more logical place to live.
We're also adding the ability to include partials from other locations in the view structure. Here's an example:
posts/index.html template could include both the post and comment forms like this:
<!-- @include form -->
<!-- @include comments/form -->
When compiling the view, Presenter would look at the following paths for the
comments/form partial, in order:
We could still override the comment form for the
posts view path by defining a
comments/_form.html partial. If the partial doesn't exist, Presenter will fall back to the
comments/_form.html partial. If that partial doesn't exist, Presenter will look for the partial in the shared partials directory.
This is a fairly simple change but I expect it to bring a lot of value to the apps we build.
Let me know what you think. Thanks for reading!