It seems that it would be helpful to have the ability to add some custom classes that are unique to each page. It would help with theming based on CSS. In the past, I have used the following:

$vars['body_classes'] .= ' ' . str_replace('/', ' ', drupal_get_path_alias($_GET['q'])) . ' ';

Not only does it add a class to the body tag for each section of the url, but it also gives you a class of the the parent page so you can do styling of the child pages of each section.

What is the most efficient way of achieving this solution?

- Brent

Comments

makara’s picture

I suggest you leave it. Normally I custom $vars['body_classes'] when I need to.

m3avrck’s picture

I'm not a big fan of these approach since aliases can change and when they do your CSS has to change with it. It's not sustainable. Also it's not the most efficient way.

drupal.org/project/context

Is one of the best ways to theme on "sections" IMO.

For more complex, see: drupal.org/project/spaces

designerbrent’s picture

Status: Active » Closed (works as designed)

That totally makes sense from that stand point @m3avrck. I recall seeing spaces and context before and it really didn't make sense at the time to me but after reviewing the video on context, I was blown away. Now I need to go dig into that because I can see there is some really good stuff there. Thanks for the links and information.

adrinux’s picture

@m3avrck For one or two page specific css tweaks surely spaces and context are overkill? That's not to say this should be added to blueprint though :) I'd also say that url alias' for major sections very rarely change, if they change often, you're doing something wrong!

I think makara is right, this is a per theme/per site customization. I just used this similar approach today:

$uri_path = trim($_SERVER['REQUEST_URI'], '/');
$uri_path_clean = str_replace(array('/', '?','='),'-', $uri_path);
$vars['body_classes'] .= ' page-' . $uri_path_clean;

to overcome the fact that theme_item_list() doesn't take account of the query argument when calculating whether an item is active and thus assigns class .active to all links in my block pointing to filtered views2 views. With a unique page url I can still have a proper active style using a descendent selector. Probably a better way to fix that though....