Reputation: 13318
This is how my application layout page is looking (here is a part of it)
%html
%body
#main
.content
= yield
Sometimes (not always) I need to add "id" attribute to .content
div
. How can I do it from a html.haml
page?
Note: I don't mean to do it in runtime using javascript.
UPDATE: thanks, but I forgot to mention that this "id" is different for each page. In other words, each html.haml
page might have its own "id" for .content
.
Upvotes: 0
Views: 673
Reputation: 4187
And another solution:
%html
%body
#main
.content{id: @content_id}
= yield
#some .html.haml page
- @content_id = "my_id"
If you don't define @content_id
then .content
would be without id.
Upvotes: 1
Reputation: 754
You can add attributes via ruby a Hash and set the value through a conditional expression.
%html
%body
#main
.content{:id => (id_needed ? 'my_id' : nil)}
= yield
Upvotes: 0
Reputation: 10701
You can do this to add attributes like id to a tag:
.content{:id => "foo"}
Upvotes: 0
Reputation: 19061
You can just daisy chain ids and classes as much as you want
%html
%body
#main
.content#random-id.random-class
= yield
Upvotes: 0