Blocks / place holders in layouts #111

ejsmith opened this Issue Feb 16, 2012 · 2 comments

3 participants


I want to provide place holders for content in my layout template that I can implement in my child templates. I have tried everything I can think of but I can only specify string values to be placed in the place holders and not complete html sections.


doctype 5
html lang: 'en', ->
  head ->
    title "#{@title} - Site" if @title?
    @headsection if @headsection?
body ->
  p 'some content'

child template

@title = 'blah'

@headsection = ->
  script src: 'blah'

p 'Child content'

please see issue #110


As maurice once said, this functionality is usually implemented in frameworks, but you should be able to do it now. At least, in a flatiron plugin I created called creamer I am able to accomplish it, by sub dividing my template into local functions. See my test example:

  describe '#attach()', ->
    it 'should allow for content_for style yields', ->
      layout = ->
        html ->
          body ->
            @header() if @header?
            @footer() if @footer?
      t = ->
        @header = -> h1 'Header'
        @body = -> p 'Hello World'
        @footer = -> footer 'Footer'
      output = htmlf """
    <p>Hello World</p>
      app = new broadway.App()
      app.use creamer, layout: if layout? then layout else null
      app.bind(t).should.equal output
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment