Index: template.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/themes/clean/template.php,v retrieving revision 1.1.2.7.2.8 diff -u -r1.1.2.7.2.8 template.php --- template.php 19 Jun 2009 11:29:51 -0000 1.1.2.7.2.8 +++ template.php 13 Jul 2009 12:42:16 -0000 @@ -38,6 +38,9 @@ function phptemplate_preprocess_page(&$vars, $hook) { $vars['path'] = base_path() . path_to_theme() .'/'; $vars['logo'] = preg_replace('@^'. base_path() .'@', '', $vars['logo']); + + // Add body classes. + $vars['body_classes'] .= phptemplate_body_classes($vars); } /** @@ -69,6 +72,35 @@ } /** + * Create body classes for page templates files in addition to those provided by core. + * + * @param $vars + * An array of variables to pass to the theme template. + * @return $classes + * A string of node classes for inserting into the node template. + * Includes the initial space ready for merging with $vars['body_classes']. + */ +function phptemplate_body_classes($vars) { + // Create classes for the user-visible path sections. + // Eg, for the path /section/subsection/page + // create: path-section, path-section-subsection, path-section-subsection-page + global $base_path; + list(,$path) = explode($base_path, $_SERVER['REQUEST_URI'], 2); + list($path,) = explode('?', $path, 2); + $path = rtrim($path, '/'); + + // Create section classes down to 3 levels. + $path_alias_sections = array_slice(explode('/', $path), 0, 3); + $section_path = 'section-path'; + foreach ($path_alias_sections as $arg_piece) { + $section_path .= '-'. $arg_piece; + $classes[] = $section_path; + } + + return ' ' . implode(' ', $classes); +} + +/** * Override or insert variables into the comment templates. * * @param $vars