Small extension for the Sinatra web framework that allows you to use the following helpers in your views:
<% content_for :some_key do %> <chunk of="html">...</chunk> <% end %> <% yield_content :some_key %>
This allows you to capture blocks inside views to be rendered later in this request. For example, to populate different parts of your layout from your view.
If you're writing “classic” style apps, then requring sinatra/content_for should be enough. If you're writing “classy” apps, then you also need to call helpers Sinatra::ContentFor in your app definition.
And how is this useful?
This only works with ERB as a rendering mechanism. I haven't figured how to make it work with Haml. If you find a way, contact me and I'll include it.
Code by foca, inspired on the Ruby on Rails helpers with the same name.