I have a partial similar to this:
/ _some_partial.md.haml
%div.container
%div.optional-row
= yield
With a view like this:
/ some_view.html.haml
---
layout: some_layout
---
= partial "some_partial" do
%p Content here
...
However, I'd like the to render some_partial
with the %div.optional-row
wrapper in some places, but not others. Is this something that can be achieved with an if/ else
statement?
I envisage the solution using content_for
and looking something like:
/ _some_partial.md.haml
%div.container
- if content_for?(:optional_row)
%div.optional-row
= yield :optional_row
- else
= yield
With
/ some_view.html.haml
---
layout: some_layout
---
- content_for :optional_row do
= partial "some_partial" do
%p Content here
...
I know this is horrendously wrong (it returns a TypeError
), but I hope it explains my thought process.
This question seems to answer mine in part, but it doesn't explain how to render the partial with the if/ else
conditions.
Ps. I'm using Middleman and so throwing in a Padrino tag