Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks / place holders in layouts #111

Open
ejsmith opened this issue Feb 16, 2012 · 2 comments
Open

Blocks / place holders in layouts #111

ejsmith opened this issue Feb 16, 2012 · 2 comments

Comments

@ejsmith
Copy link

ejsmith commented Feb 16, 2012

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.

layout

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

child template

@title = 'blah'

@headsection = ->
  script src: 'blah'

p 'Child content'
@gradus
Copy link

gradus commented Mar 30, 2012

please see issue #110

@twilson63
Copy link

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 ->
            content()
            @header() if @header?
            @body()
            @footer() if @footer?
      t = ->
        @header = -> h1 'Header'
        @body = -> p 'Hello World'
        @footer = -> footer 'Footer'
      output = htmlf """
<html>
  <body>
    <h1>Header</h1>
    <p>Hello World</p>
    <footer>Footer</footer>
  </body>
</html>
      """
      app = new broadway.App()
      app.use creamer, layout: if layout? then layout else null
      app.init()
      app.bind(t).should.equal output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants