custom page-xxxx.tpl.php doesnt works

2019-07-21 02:58发布

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?

1条回答
We Are One
2楼-- · 2019-07-21 03:28

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.

查看更多
登录 后发表回答