0

I have looked but it seems I can't find the right answer or I don't have the skills for that. The thing is I'm getting this error:

Notice: Undefined variable: node in include() (line 69 of /home/xwebmedia/public_html/ltr/sites/all/themes/ltr/page.tpl.php).

and the code I'm using is:

<?php
if (count($node->field_adds) != 0)
{
    foreach($node->field_adds['und'] as $key => $value)
    {               
        $nid = $value['nid']; 
        $mywidget = node_view(node_load($nid));
        print drupal_render($mywidget);
    }       
}
?>

Thing is everything is working fine, I get my widgets with adds in sidebar, but I am having this notice of error.

I know that I need to define a variable in template.php but I tried something it didn't work.

Any suggestions?

2 Answers 2

2

Check that $node has been set.

<?php
if (isset($node) && count($node->field_adds) != 0)
{
    foreach($node->field_adds['und'] as $key => $value)
    {               
        $nid = $value['nid']; 
        $mywidget = node_view(node_load($nid));
        print drupal_render($mywidget);
    }       
}
?>
Sign up to request clarification or add additional context in comments.

Comments

0

The page template file doesn't have a $node variable by default (you can have pages that aren't nodes so it's not required).

The menu_get_object() function is your friend here:

$node = menu_get_object();
if ($node) {
  ...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.