Creating content to work with Slim

I am working on implementing support for content_for and yield_content in Hardwired .

The Sinatra :: Contrib implementation does not work, so I tried a simpler version:

module ContentFor def content_for(key, &block) content_blocks[key.to_sym] << block.call return "" end def content_for?(key) content_blocks[key.to_sym].any? end def yield_content(key, *args) content_blocks[key.to_sym].join end private def content_blocks @content_blocks ||= Hash.new {|h,k| h[k] = [] } end end 

Unfortunately, this repeats the content (content_for seems to capture everything in the template, not just the child content).

What approach should be used to implement this?

+4
source share
1 answer

Slim only captures child content if you use = or == rather than - .

Just use = content_for :area do instead - content_for :area do

Note. Obviously, this problem is specific to the Sinatra content_for and yield_content . Apparently, a more sophisticated Rails implementation allows you to use buffer magic to make this possible with - .

+4
source

All Articles