7

I have some Haml partials, many of which contain the boilerplate

.container .row .col-lg-12

When I try to abstract that out ala = partial "site_section", I get:

syntax error, unexpected keyword_end, expecting end-of-input end;end;end;end

I'm using ruby 2.2.2.

How do I render a Haml partial within a Haml partial in Middleman?

Thanks

update This is apparently some kind of special case dealing with my partial (above). I have other partials-within-partials rendering just fine.

update With respect to this this repo, the layout would actually be:

_site_section:

.container .row .col-lg-12

_nested_section:

= partial "site_section"
  MOAR (nested) HAML

index.haml:

=partial "nested_section"

5
  • Can you post your file _site_section.haml?
    – acsmith
    Apr 20, 2015 at 18:53
  • That's it, above: .container etc Apr 20, 2015 at 19:14
  • @acsmith there's a bounty, tell your friends. Apr 25, 2015 at 1:13
  • I just tried but could not reproduce it , look at github.com/chischaschos/middleman-test. Is that the way you are using it? Apr 25, 2015 at 18:10
  • @chischaschos thanks i replied to you above in the question. Apr 25, 2015 at 20:38

1 Answer 1

1

Because of the way HAML works the following is invalid:

= partial "site_section"
  MOAR (nested) HAML

If you want to add more text or HAML then you can achieve it for example by putting the text at the same level of the previous line

= partial "site_section"
MOAR (nested) HAML

Or nesting it within a div:

= partial "site_section"
.more   
  MOAR (nested) HAML

So If what you are trying to do is to nest extra HAML to the output of the site_section partial, then you have to put the nested extra HAML in the nested partial:

.container
  .row
    .col-lg-12
      = partial 'nested_stuff'
= partial 'nested_stuff'

Hope this helps, I updated the repo with the working example.

5
  • putting it on the same level as the previous line doesn't work. the styling of "site_section" is not applied to the partial. nesting it within a dive (.more), also on the next line, doesn't work, for the same exact reason. your third example doesn't make any sense to me. it wouldn't give me what i'm looking for. Apr 28, 2015 at 5:07
  • Oh then I think I don't understand what you are trying to achieve, what would be the expected output html? Apr 28, 2015 at 11:58
  • thanks for hanging in there. I'm trying to abstract out the .container .row .col-lg-12 into its own partial (_site_section.haml), for use in other partials. each partial would be able to express additional content, nested under _site_section. The equivalent would be what I already have working, which is just to repeat .container .row .col-lg-12 in ever partial, followed by new content nested underneath. Apr 28, 2015 at 16:13
  • Seems like the only way could be to provide a block to the partial as in github.com/middleman/middleman/issues/1099. My example would then become github.com/chischaschos/middleman-test/blob/master/test/source/…. Apr 29, 2015 at 12:34
  • again, thanks for hanging in there. adding the do block doesn't yield text or haml, even if prefixed with a puts. this could possibly be because the mixin functionality was never actually merged with middleman master. even if one could use it, you'd have to use =mixin, etc. that link is good, though. it looks like there might be a solution possible from the building blocks he gives where he says "vanilla partial". Apr 29, 2015 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.