0

I'm a trying to pass a var, in this case the var "$node" to the page.tpl.php. Tried everything for three days but i cannot make it work despite my code is correct apparently. Tried different ways but when i tried to check with isset if the var exists, it returns false. I really need it, so i can check pages and nodes.

This is my code:

template.tpl.php

  function agn_preprocess_page(&$vars) {
  $node = menu_get_object();
  if ($node = menu_get_object()) {
      $vars['node'] = $node->type;
  }
  }

page.tpl.php

<?php if (isset($node)){
   print "true";
}else{
   print "false";
}
?>

Thanks in advance!

3
  • Interesting ... but what is your actual question? Feb 1, 2017 at 15:44
  • Why overwrite node with the node type?
    – Kevin
    Feb 1, 2017 at 16:01
  • The question IS that i cannot make the node variable to work. It keeps retutning false when i Check if exists...
    – HomerO
    Feb 1, 2017 at 16:30

1 Answer 1

1

$node is already available in page.tpl.php on node pages without you having to do anything. See the documentation

3
  • Thanks but it keeps me showing false when i Check with isset. And It gives me node IS not defined.
    – HomerO
    Feb 1, 2017 at 16:24
  • Are you actually on a node page?
    – Jaypan
    Feb 1, 2017 at 16:31
  • Gave me true... I was am idiot that i didnt try that...
    – HomerO
    Feb 1, 2017 at 17:04

Your Answer

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

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