specify Id of the body on a comatose page

0 views
Skip to first unread message

Mick Delaney

unread,
Dec 18, 2008, 6:47:27 AM12/18/08
to Comatose Plugin
hi,

i'm using comatose for a project. i have a tab navigation system where
i need to specify a id on the body and use a decendent css selector to
style the current tab.

#body_contactus #contactus {color: red;}

i have an instance variable on the layout
<body id="<%= body_id %>">
which i can then set on a view page <% body_id="contact_us" %>

whats the easiest way for me to specifiy an Id on the body from within
a comatose page??? is it using a drop or something. (i'm a comatose
newbie)

regards.

MRoderick

unread,
Dec 18, 2008, 5:02:51 PM12/18/08
to Comatose Plugin
You can just stick it into the keywords field, and then create a
helper method to extract it from the page.

Example keyword
body_id:contact_us

def body_id( page )
...
end

We've used it for similar purposes several times (like excluding pages
from navigation, etc), and have yet to run into problems.

M@ will have to speak up, if he has other intentions for the keywords
attribute ;-)

/morgan

Mick Delaney

unread,
Dec 18, 2008, 5:38:42 PM12/18/08
to Comatose Plugin
is there an example of this available. as i said i've just started
using comatose. do i need to hook into the page processing??
thanks again for help.

MRoderick

unread,
Dec 19, 2008, 4:54:47 AM12/19/08
to Comatose Plugin
You could just do something like this:

# application_helper.rb
def body_class( page )
page.keywords.scan(/body_class:([^ ]*)/).to_s
end

# layout file
<body class="<%= body_class( @page ) %>">

In your helper you could also navigate upwards in the page tree, until
you find a page with a body_class, but this should be enough to get
you started :-)

MRoderick

unread,
Dec 19, 2008, 4:57:25 AM12/19/08
to Comatose Plugin
Oh, it was the body_id you were after, and not body_class.

The mechanics are the same though :-)
Reply all
Reply to author
Forward
0 new messages