adams.co.tt

Rendering partials in toto

19th April 2012

toto is a fantastic lightweight blogging engine. In fact, at the time of writing, this very blog is running on it. By looking at dorothy you can see how it uses a layout and templates to render content. However, by default, it does not provide support for template partials.

However, that’s easily solved with a little monkey patching:

module Toto
  class Site
    class Context
      def to_partial(page)
        to_html page, @config
      end
    end
  end
end

Now you can include partials in your templates like this:

<%= render 'sidebar', :partial %>

Now, I’m not a fan of monkey patching for a number reasons, not least of which is the fact that a good monkey patch is often a missed opportunity to improve an open source project. With that in mind, here is the pull request to have this functionality added to toto itself.

tags: toto, ruby, post
blog comments powered by Disqus