自定义页面-xxxx.tpl.php 不起作用 [英] custom page-xxxx.tpl.php doesnt works

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

问题描述

我有一个名为 page--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;
    }
}

假设您的节点类型为news",那么 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天全站免登陆