The new $body_classes variable is a boon to theme designers. But why limit ourselves to just classes?
In XHTML, there are many possible valid attributes for the body tag, including the extremely powerful id and style attributes among others. The body tag even allows a title attribute.
According to the documentation the $body_classes variable may retrieve something like:
front logged-in node-type-page no-sidebars
which still needs to be surrounded by additional class="" markup before it is of any use in a template.
Instead, $body_attributes could take advantage of drupal_attributes()and return something more flexible and useful like:
class="front logged-in node-type-page no-sidebars" id="nid-457" style="background-image: url(example.jpg)"
I currently implement this method on all of my themes and it is extremely useful, especially for dynamically changing the entire background image for a page.
Comments
Comment #1
Crell commentedI can definitely see how this would be useful, but a more standardized pattern for how classes, styles, and ids should be defined is needed. That should be discussed in more depth here: http://groups.drupal.org/node/6355
This is definitely Drupal 7 material, though.
Comment #2
dvessel commented+1 and subscribing
Comment #3
siteograf commentedIt's not good idea to use style attribute in tags - we need to separate content from presentation. And using id attribute in body also not so good practice, because there can be situation when drupal developer need to have both attributes nid and his custom id, but he can't - there can't be more than one id per tag.
Comment #4
webchickWe're past code slush now, so this'll have to be a D8 thing.
Comment #5
johnalbinAnd there's no $body_classes variable in D7.