To my (untrained) eye, the downside to the vanilla if block to me eye
is that the hierarchical structure of the html (haml) is perverted by
the if clause control flow.  The 99% of the time, %div really wants to
be directly underneath the containing element, not underneath the
silent-eval if, imho.

I guess it seems slightly odd to me that &= and != and == get special
treatment as syntactic sugar, but this other (common?) case does not.
After all, we could use the argument to require

= h(foo)

in lieu of &=, != etc.

I appreciate everyone's feedback tho - clearly there isn't a
groundswell of interest in this addition :-).  I can easily live eith
the status quo or the :conditional_tag(:div) which fits on a single
line and mostly serves my needs just fine.

On Jul 19, 4:32 pm, "G. Sobrinho" <[email protected]> wrote:
> Why not use the if?
>
> - if foo.subject.present?
>   %div Hello
>
> This is clean and readable for all situations
>
> 2009/7/19 grimen <[email protected]>
>
>
>
>
>
> > Agree. Create a helper like:
>
> > = conditional_tag(:div, :if => foo.subject.present?) do
> >  = "Hello"
>
> > grimen
>
> > On Jul 18, 7:32 pm, Nathan Weizenbaum <[email protected]> wrote:
> > > I feel like, in this case, the more explicit way of writing it is best.
> > If
> > > we do add the language feature, most people won't know about it and will
> > > become confused upon seeing it in someone else's code, which isn't worth
> > it
> > > for something that can be easily done without a language feature.
>
> > > You could write a helper for it, though.
>
> > > On Sat, Jul 18, 2009 at 9:02 AM, ehahn <[email protected]> wrote:
>
> > > > Hi.  Newbie alert (apologies!)
>
> > > >  I'm really loving haml but very frequently finding starting with:
>
> > > > %div= foo.subject
>
> > > > and then not liking the empty html elements when there is no subject,
> > > > so I dutifully improve the output with:
>
> > > > - unless foo.subject.blank?
> > > >  %div= foo.subject
>
> > > > I'm wondering if there is a shorthand for this (common?) usage in
> > > > haml?  I guess what I'd love to see is something like:
>
> > > > %div=? foo.subject (and %div!=? etc.)
>
> > > > which would mean "only emit the html if the expression evaluates to a
> > > > non-blank value"
>
> > > > Is there some fantastic way to achieve this with released haml?
>
> --
> Regards,
>
> Gabriel Sobrinho
> E-mail: [email protected]
> Phone: +55 31 8775 8378
>
> Don't print this e-mail. The nature is thankful and your money also.
--~--~---------~--~----~------------~-------~--~----~
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