Try something like this...define a helper like:

def conditional_div(condition, attributes, &block)
  if condition
    haml_tag :div, attributes, &block
  else
    haml_concat capture_haml(&block)
  end
end

Then, in your template do:

- conditional_div(!skip_outer, {:id => "some_id"}) do
  / some content here

On Jun 29, 6:33 am, Cataclyst <[email protected]> wrote:
> Hi all,
>
> so far I've been using haml with joy, but now I'm having a problem I'm
> not able to solve: I want to nest content within a div, but only if a
> specific local variable is true. The idea is to render a partial with
> or without the surrounding "container" div just as needed, in order to
> render a new item block or just replace the content within it (as an
> AJAX response).
>
> In ERB, I would do something similar to the following:
>
> ######
>
> <% if !skip_outer -%>
>   <div id="some_id">
> <% end -%>
>
>  <!-- some content here -->
>
> <% if !skip_outer -%>
>   </div>
> <% end -%>
>
> #######
>
> How do I accomplish the same thing with HAML? If-then statements don't
> really work:
>
> - if !skip_outer
>   #some_id
>   / content here would be rendered only on !skip_outer, and even not
> within the div#some_id
>
> neither does it with an else case:
>
> - if !skip_outer
>   #some_id
> - else
>   / content here would be rendered only on skip_outer
>
> Any ideas to get something like that work "gracefully", i.e. without
> having to double the content in both if-else-branches?
>
> Thanks in advance.
> André
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Haml" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/haml?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to