I am using smarty but this isn't a smarty only solution.
I've been looking for a couple weeks now for a way to give the body an id based on the module or node I was pulling up. This solution is pretty simple and I may be reinventing the wheel here. Please let me know if there's a better way to do this.
function get_body_id(){
$q = $_GET['q'];//In my code I actually check post and query string with a function I made, but this will work also
$body_id = str_replace('/','-', $q);
return $body_id;
}
In the body tag I just call the function like so: <body id="{php}echo get_body_id();{/php}" {if $node}class="node"{/if}>
. Now for you non smarty users you'd use: <?php= get_body_id(); ?>
. Notice that I also put a conditional statement that will identify the page as displaying a node, which helps me identify node pages from everything else.
This solution will just print out the module id for the body id or "node-1" (for example) if the page is a node. It works pretty well for most of the things I am doing but I don't know how well it would work for complicated page calls.
The beauty of id tags is that I can just ignore the tags for arbitrary pages.
Is there something out there better than this? Does drupal have something built-in? I've been looking around for a while but I haven't found anything. If there isn't they need to include that in a future release because body id's, classes are the only way to get ultimate flexibility in theming (I know bc my designer has been yelling at me ab this for days).