0

Im using

views_embed_view('view_name', 'view_block_name', $node->nid);

and im getting error Notice: Undefined variable: node in functin include() So in D7 We cant use $node inside page.tpl.php?

  • The answer is theme dependent. What theme are you using? – keithm Aug 7 '11 at 19:50
1

If you are using drupal 7, there should already be a node object available when you are looking at a full node page. Looking at http://api.drupal.org/api/drupal/includes--theme.inc/function/template_preprocess_page/7 - the default implementation embeds it into the $variables array:

  if ($node = menu_get_object()) {
    $variables['node'] = $node;
  }

If your theme is overriding this, you can simply add it back in.

An example might be:

function YOURTHEME_preprocess_page(&$variables) {
  if ($node = menu_get_object()) {
    $variables['node'] = $node;
  }
}
  • so as you said this error wouldnt appear at all? Im not overiding $node in my theme. – Alexander Kim Aug 8 '11 at 5:18
  • If your theme implements hook_preprocess_page() and fails to declare the $variables['node'] parameter then $node will be missing from page.tpl.php. Fortunately this is easy to rectify - see my code snippet above ;) – wiifm Aug 8 '11 at 6:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.