I am using this function on a D7 site to template based on url alias and everything works except when a page has a dash in it.
For example mysite.com/test-page doesn't work. I tried page--test-page.tpl.php
and no luck. If I change to testpage and use page--testpage.tpl.php
it works.
Any ideas?
Here is the function that works:
function mytheme_preprocess_page(&$variables) {
// Get the alias for the page being viewed
$alias = drupal_get_path_alias($_GET['q']);
if ($alias != $_GET['q']) {
$template_filename = 'page';
//Break it down for each piece of the alias path
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '__' . $path_part;
$variables['theme_hook_suggestions'][] = $template_filename;
}
}
}