I have a somewhat related question
Could I use this technique to conditionally nest some content? I'm
sorry if this is obvious from the last response, but I didn't get it
yet.
I want to render some columns and in the controller I determine how
many items should be in each column.
the markup I am trying to get is someting like
%div#col_0
ul.group
li.item
li.item
li.item
ul.group
li.item
li.item
%div#col_1
ul.group
li.item
ul.group
li.item
li.item
from index.html.haml I am calling render :partial on group and from
that partial I render :partial item
So I need to be able to conditionally start / end the column div in
the group partial.
How should I go about this?
Thanks,
Noel
On Mon, Jun 29, 2009 at 7:31 PM, Nathan Weizenbaum<[email protected]> wrote:
> Or more directly,
>
> def haml_tag_if(condition, *args, &block)
> if condition
> haml_tag *args, &block
> else
> yield
> end
> end
>
> That might be something worth adding to Haml::Helpers. Thoughts?
>
> On Mon, Jun 29, 2009 at 11:28 AM, Cataclyst <[email protected]> wrote:
>>
>> That's it, the helper method works great. :) Thanks a lot, Scott.
>>
>> André
>>
>> On 29 Jun., 18:50, scottwb <[email protected]> wrote:
>> > 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
-~----------~----~----~----~------~----~------~--~---