Nathan's technique would of course work, but I'm always hesitant to put
styling into my HTML much less my templates.
What about separating the concerns a little...
In the controller/RJS:
@visibility = hidden ? 'hidden' : visible
in the haml template:
div{:id => "my_id", :class => @visibility}
In the sass file:
.hidden
:display none
Or, let's say you have many of whatever this thing is....
@visibility["my_id"] = hidden ? 'hidden' : visible
and in the haml
div{:id => "my_id", :class => @visibility["my_id"]}
I could see an argument that this looks like more work, but it is a lot more
flexible in the future. Think, for instance, what if you need a third
state? Visible/Hidden/Highlighted? Putting a boolean all over your
templates will require a lot of replacing. Assigning a variable in the
controller logic can centralize the work.
Just a thought,
Jeff
On 12/14/07, Nathan Weizenbaum <[EMAIL PROTECTED]> wrote:
>
>
> If you pass an attribute a nil value, it won't render. Thus you can do
> something like
>
> .my_class{:id => "my_id", :style => hidden ? 'display: none' : nil}
>
> - Nathan
>
> KJoyner wrote:
> > Within my haml template, I was trying to add a :style => 'display:
> > none' to a div depending on a ruby local variable being passed into my
> > haml template.
> >
> > I am able to do this with the following code but it only works if
> > there are no other attributes:
> >
> > .my_class{ hidden ? { :style => 'display: none' } : {} }
> >
> > However, if I have other attributes such as :id => then I cannot get
> > it to work. For example,
> > .my_class{ :id => "my_id", hidden { :style => 'display: none' }}
> > does not work
> >
> > I also tried the following but could not get it to work
> >
> > - class_attributes = { :id => "my_id" }
> > - if hidden
> > class_attributes.merge( { :style => 'display: none' })
> >
> > Thanks for any help,
> >
> > -- Ken
> > >
> >
> >
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---