i try to load a node in Drupal 7 in a php file, which will be loaded with ajax.

my php file looks like this:

require_once '../../../includes/bootstrap.inc';
$i = 16;
$content = node_load($i);

The include of bootstrap.inc works fine, but this file returns 'PHP Fatal error: Call to undefined function node_load()'. i guess i've read that the function node_load needs the bootstrap.inc file, but it doesnt seems so.

Is there any possible way to use the node_load function right without 'register' a module in drupal - i just want to load a self made php file, which just returns the content of a node - without the template!


3 Answers 3


Rather than using a custom php file you should attempt to solve the issue "the drupal way" via a custom module or in your template.php... Please see my answer in this question.

It explains how you can add to the original url to change the template (or create a blank template so it is only node data presetned).

  • Arent there solutions to realize it without the template.php and without creating drupal-like functions ?
    – Timo
    Commented Jun 11, 2012 at 10:25
  • 1
    You can but then what would be the point of Drupal and its awesome framework / api. Using Drupal functions is really very easy, even more so than custom php once you are over the initial learning curve.
    – WestieUK
    Commented Jun 11, 2012 at 10:50

7 node.module node_load($nid = NULL, $vid = NULL, $reset = FALSE)

node load API is in node.module file. You probably need to include this file to get it working, but I suggest not to take this approach. If you dont want to write a separate module then add your functions to theme files. Its better to create a module or edit any existing modules and make a note that you have edited just in case you upgraded it then it will be over written.


Please paste this code in the start of PHP file


    define('DRUPAL_ROOT', getcwd());

    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';

Hope it will work!!

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.