自定义页面xxxx.tpl.php无效 [英] custom page-xxxx.tpl.php doesnt works

查看:154
本文介绍了自定义页面xxxx.tpl.php无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有页面命名页面 - news.tpl.php,我为我的新闻页面创建。但是,当我清除我的缓存后,页面仍然没有使用,drupal使用原始的page.tpl.php。任何想法如何解决?

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?

推荐答案

另一种做法是通过预处理钩子,几行代码。
这是怎么回事

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;
    }
}

假设你有一个节点类型为新闻 tpl应该看起来像page - news.tpl.php,上面的代码将处理其余的。

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

这篇关于自定义页面xxxx.tpl.php无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆