Posted by jucallme on October 29, 2010 at 8:34pm
function phptemplate_preprocess_page(&$vars) {
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$suggestions = array();
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '--' . $path_part;
$suggestions[] = $template_filename;
}
$vars['template_files'] = array_merge((array) $suggestions, $vars['template_files']);
}
}
}what is the D7 equivalent for this anyone... sorry don't get this stuff 2 much.
Comments
EXTENDING DRUPAL TEMPLATING
Here we go something that works for Drupal 7, I'm still having to override phptemplate with my theme name. Don't know why that HAS to happen.
function phptemplate_preprocess_page(&$vars)
{
//the path module is required and must be activated
if(module_exists('path'))
{
//gets the "clean" URL of the current page
$alias = drupal_get_path_alias($_GET['q']);
$suggestions = array();
//keep the values drupal has generated
$suggestions = $vars['theme_hook_suggestions'];
$template_filename = 'page';
$isFirst = TRUE;
foreach(explode('/', $alias) as $path_part)
{
//only add '__' if its the first split else only add '_'
if ($isFirst) {
$isFirst = FALSE;
$template_filename = $template_filename.'__'.$path_part;
$suggestions[] = $template_filename;
} else {
$suggestions[] = $template_filename. '_' .$path_part;
}
}
$vars['theme_hook_suggestions'] = $suggestions;
}
}
Looks like the D7 beta-2 has some bugs as according to http://www.slideshare.net/pingv/grok-drupal-7-theming?from=ss_embed slide 82 there should only be one '--'. But if you out put the debug
echo '<pre>';
print_r($vars['theme_hook_suggestions']);
echo '</pre>';
You will see that the core generates values of
Array
(
[0] => page__node
[1] => page__node__%
[2] => page__node__17
)
Is in the code I have assumed this is a bug... reporting it now.