Making content_for work with Slim

ruby, sinatra, slim-lang

Solution

Slim only captures child content if you use `=` or `==`, not `-`.

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

Note: Apparently this issue is specific to the Sinatra-style `content_for` and `yield_content`. Apparently the more sophisticated Rails implementation manages to use buffer magic to make this possible with `-` as well.

Problem

I'm working on implementing content_for and yield_content support in Hardwired. The Sinatra::Contrib implementation doesn't 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 content (content_for seems to grab everything in the template, not just child content). What approach should I take to implementing this?

Original source