开发者

Why isn't $vars['node'] available in preprocess_page for some content types?

开发者 https://www.devze.com 2022-12-17 09:38 出处:网络
I am currently using drupal 6 for a site I\'m working on. I have a MYTHEME_preprocess_page() function that adds a few variables to the page.tpl.php template from the taxonomy and from a cck field. It

I am currently using drupal 6 for a site I'm working on. I have a MYTHEME_preprocess_page() function that adds a few variables to the page.tpl.php template from the taxonomy and from a cck field. It was working correctly for a bit, and then the $vars['node'] is empty, but only for 2 content types. The 'node' variable is available to the preprocess_page function in other content types.

I thought it was a problem with using the following code, but when I remove all of this, the 'node' variable is still empty.

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

Does anyone know of any gotchas or bugs that might be removing the 'node' variable? I can't seem to figure out where I'm going wrong. I'm at a loss.

Here is my complete mytheme_preprocess_page() function.

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_f开发者_StackOverflowirst_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>';
      }
    }
  }
}


After going through and disabling modules one-by-one, I determined that the problem is related to the module, node_breadcrumb. A similar issue was filed here: http://drupal.org/node/616100#comment-2199374

In the 3rd comment, you'll see a link to another issue with a resolution


For others that run into this, I had the same issue as a result of using the jQuery UI module. Disabling and re-enabling fixed it, and I could not track down the specific issue, but it appeared to be related to $static variables in some path check functions.

To others that stumble their way into here, I suggest you pull some of the more obvious modules right out of the module folder on your dev setup, see if things change, and then put them back in there until you figure it out.

Another option is to search for instances of _preprocess_page(, $variables['node'] and $vars['node'] to see if some contributed code is unwittingly unsetting a node when it shouldn't be.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号