How to rendering partials within a partials in middleman
Asked Answered
W

1

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"

Wellbred answered 20/4, 2015 at 16:2 Comment(5)
Can you post your file _site_section.haml?Collectivize
That's it, above: .container etcWellbred
@Collectivize there's a bounty, tell your friends.Wellbred
I just tried but could not reproduce it , look at github.com/chischaschos/middleman-test. Is that the way you are using it?Oeo
@Oeo thanks i replied to you above in the question.Wellbred
O
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.

Oeo answered 26/4, 2015 at 14:42 Comment(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.Wellbred
Oh then I think I don't understand what you are trying to achieve, what would be the expected output html?Oeo
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.Wellbred
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/….Oeo
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".Wellbred

© 2022 - 2024 — McMap. All rights reserved.