Drupal 7 Template Suggestions -- Why is this not working?
I've created my own theme. In the template.php file, I have the following code:
function mytheme_preprocess_page(&$variables) {
if(isset($variables['node'])){
if($variables['node']->type === 'sports'){
$variables['theme_hook_suggestions'][] = 'page__node__sports';
}
}
}
And I have a page_node_sports.tpl.php file in my theme's template directory, and I have cleared the cache. However, the page_node_sports.tpl.php template doesn't get used. Doing some debugging, I stuck an echo statement at the beginning of the preprocess_page function, and that did appear onscreen, so I know the function is running. But the template suggestion just isn't working. I even removed the if statements insid开发者_C百科e the function, leaving just the $variables['theme_hook_suggestions'] = ... line, but still nada.
Any idea what's going wrong?
Have you also added a page.tpl.php to your theme folder? Suggestions only work if the original template exists too.
See also http://adaptivethemes.com/page-template-suggestions-per-node-type
Figured it out. Although the template name in the line:
$variables['theme_hook_suggestions'][] = 'page__node__sports';
should have underscores, the actual .tpl.php file should have hyphens instead.
精彩评论