为什么某些内容类型的preprocess_page中没有$ vars ['node']?

时间:2010-01-20 23:23:56

标签: drupal templates drupal-6

我目前正在使用drupal 6来处理我正在处理的网站。我有一个MYTHEME_preprocess_page()函数,它可以从分类法和cck字段向page.tpl.php模板添加一些变量。它正常工作了一段时间,然后$ vars ['node']为空,但仅适用于2种内容类型。 'node'变量可用于其他内容类型中的preprocess_page函数。

我认为使用以下代码是一个问题,但是当我删除所有这些时,'node'变量仍为空。

function mytheme_preprocess_node(&$vars, $hook) {
  $function = 'mytheme_preprocess_node'.'_'. $vars['node']->type;
  if (function_exists($function)) {
   $function(&$vars);
  }
}

有没有人知道可能删除'node'变量的任何问题或错误?我似乎无法弄清楚我哪里出错了。我很茫然。

这是我完整的mytheme_preprocess_page()函数。

function mytheme_preprocess_page(&$vars, $hook) {
  if ($hook == 'node' || $hook == 'page') {

    if (is_object($vars['node'])) {
      // grab the header image if it exists to make it avaialble to the content header
      $vars['header_image'] = _mytheme_get_header_image($vars);

      // get the taxonomy term to put in the content header
      if (count($vars['node']->taxonomy) > 0) {
        $vars['tax_term'] = "<div class=\"terms\">" . _mytheme_get_first_taxonomy_term($vars['node']->taxonomy) . "</div>";
      }

      // add the teacher's credentials to the content header
      if ($vars['node']->field_credentials[0]['view'] != '') {
        $vars['teacher_credentials'] = '<span class="teacher-creds">' . $vars['node']->field_credentials[0]['view'] . '</span>';
      }
    }
  }
}

2 个答案:

答案 0 :(得分:1)

在逐个执行并禁用模块之后,我确定问题与模块node_breadcrumb有关。此处提交了类似的问题:http://drupal.org/node/616100#comment-2199374

在第3条评论中,您会看到指向其他问题的链接

答案 1 :(得分:0)

对于遇到此问题的其他人,由于使用了jQuery UI模块,我遇到了同样的问题。禁用和重新启用修复它,我无法追踪具体问题,但它似乎与某些路径检查函数中的$ static变量有关。

对于那些偶然发现的人来说,我建议你从开发设置的模块文件夹中拉出一些更明显的模块,看看是否有变化,然后把它们放回去,直到你搞清楚

另一种选择是搜索_preprocess_page($variables['node']$vars['node']的实例,以查看某些贡献代码是否无意中取消了该节点的设置。