Search code examples
drupaldrupal-7drupal-theming

custom page-xxxx.tpl.php doesnt works


I have page named page--news.tpl.php, which i created for my news page. But after i cleared my cache, page still not using, and drupal use the original page.tpl.php. Any ideas how to solve it?


Solution

  • An alternate way of doing it, is through preprocess hook with few lines of code. Here's how it goes

    function <module_name>_preprocess_page(&$variables) {
        if (isset($variables['node'])) {
            $variables['theme_hook_suggestions'][] = 'page__'.$variables['node']->type;
        }
    }
    

    Suppose you have a node type as "news" then tpl should look like 'page--news.tpl.php' and above code will handle the rest.