content_for in sinatra : http://proccli.com/railslike-contentfor-sinatra
<div id='sidebar'> | |
<%= section(:sidebar) || partial(:default_sidebar) %> | |
</div> |
module Sinatra::Helpers | |
def section(key, *args, &block) | |
@sections ||= Hash.new{ |k,v| k[v] = [] } | |
if block_given? | |
@sections[key] << block | |
else | |
@sections[key].inject(''){ |content, block| content << block.call(*args) } if @sections.keys.include?(key) | |
end | |
end | |
end |
<% section(:sidebar){ partial :custom_sidebar, :local1 => blah, :local2 => blah } %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment