Th current body class system adds on the following classes to the body by default (from http://api.drupal.org/api/function/template_preprocess_page/7):

  1. Front page identification: front / not-front
  2. User logged in status: loggen-in / not-logged-in
  3. Page type such as page-node, page-user, etc: 'page-' . arg(0) cleaned up
  4. If on a page displaying or editing a node: 'node-type-'. $type
  5. Sidebars indication: two-sidebars / no-sidebars / one-sidebar sidebar-left / one-sidebar sidebar-right (looks for blocks in regions 'left' and 'right')

Compare this to the template suggestions system, which walks through the whole path and suggests more sensible file names. Excerpt from the code docs inside this same function.

  // [...] For example,
  // http://www.example.com/node/1/edit would result in the following
  // suggestions:
  //
  // page-node-edit.tpl.php
  // page-node-1.tpl.php
  // page-node.tpl.php
  // page.tpl.php

Bringing this same flexibility over to the body classes would be highly useful, and would allow for things like styling blocks differently on the node editing pages (body.node-edit) or styling the user profile differently for the blog author/admin (body.user-1) or styling certain regions in special ways on an Ubercart checkout page (body.cart-checkout). This system goes beyond the first argument in the path (such as node, user and cart in these cases), thus allowing for more versatile theming. Before this patch, these pages only get page-node, page-user and page-cart classes. After my patch, checking for the checkout, user 1 or node edit screen becomes trivial from CSS.

After the patch, the same code comment documenting the behavior becomes:

  // [...] For 
  // example, http://www.example.com/node/1/edit would result in the following
  // suggestions and body classes:
  //
  // page-node-edit.tpl.php  page-node-edit
  // page-node-1.tpl.php     page-node-1
  // page-node.tpl.php       page-node
  // page.tpl.php

Let's improve our toolset for themers in CSS! They deserve the same flexibility as with the theme file suggestions :)

Comments

johnalbin’s picture

Zen does this. D6 core's page-arg0 class is completely useless because it usually results in a class called "page-node". And what good is that?

I'll add "review this" to my to-do list. Shouldn't take too long to do, but no time this sec. :-)

johnalbin’s picture

Issue tags: +CSS, +theme
dries’s picture

Status: Needs review » Reviewed & tested by the community

This makes a lot of sense to me. It improves consistency considerably and seems to give themers more power. I'm marking this RTBC and will proceed committing this unless someone has strong objections.

johnalbin’s picture

Ok. I just reviewed this patch. This almost exactly the way Zen does it but more efficient because you are leveraging the suggestion code in template_preprocess_page() Nice!

RTBC+1 then.

dries’s picture

Status: Reviewed & tested by the community » Fixed

Alright, thanks for verifying. I committed this to CVS.

Status: Fixed » Closed (fixed)
Issue tags: -CSS, -theme

Automatically closed -- issue fixed for 2 weeks with no activity.