jacksonemg
jacksonemg

Reputation: 23

Get Node info in PHP Code Formatted Text Field

In Drupal 7, I have a content type with a text field that's being formatted to process php. If I create an instance of that content type is there a way to get information about the node in the code?

So my text field has:

<?php print $node->nid; ?>

I get the error:

  • Notice: Undefined variable: node in eval() ...
  • Notice: Trying to get property of non-object in eval() ...

Also doing this does not work (I get the same undefined error for $nid):

<?php
    $node = node_load($nid);
    print_r($node);
?>

Is there any way to retrieve information about the node this way?

Upvotes: 1

Views: 2133

Answers (2)

useful
useful

Reputation: 472

You can call

$node  = menu_get_object();

Upvotes: 2

thtas
thtas

Reputation: 380

have you tried getting the nid from the args?

e.g.

if(is_numeric(arg(1))
{
    $nid = arg(1);
    $node = node_load($nid);
    print_r($node);
}

Maybe if you describe the problem you're trying to solve it will help. There a probably better, more manageable solutions to your problem which don't involve a php formatted textfield. Generally evaluating php like this should be a last resort only ;)

Upvotes: 0

Related Questions