Quick question.
I need to access another's node content from a general file (not drupall page/node etc), how do I do it?

I'm doing following in a file myfile.php

include ("page-node-123.tpl.php");

in the page-node-123.tpl.php file i'm printing the contents of node 123.

So ultimately i should be able to see the contents of node 123 in file myfile.php?

Am I doing something wrong?

node variables are not working in this way?

Comments

DaveS98’s picture

I think what I said was not correct.

What I need to do is to print a node's content from any .php file. I know the node id and I want to get the contents of this node.

ajaykumarsingh’s picture

You can run sql query on db to get the contents directly as you already know node id.

heytrish’s picture

creating node-xx.tpl.php only creates a template for that specific node. Content is not stored in that file, its stored in the database. There is however, little tricks to acquire contents (body/teaser) from a specific node and insert into another node. One way, if this is a one time content creation, is to directly access the node via mySQL queries. Another way, is to use Views to select xx node(s) and insert it into the body of another node ( http://drupal.org/node/85769 ). More examples of inserting views ( http://drupal.org/node/48816 ).

I haven't used this, but I think this could be what you are looking for: Insert contents of node xx into node zz
http://drupal.org/project/InsertNode

To create a file outside of Drupal, you need to access drupal in order to access node content (the other way would be to create sql queries)

myfile.php

require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

$node = node_load(array('nid'=>'123'));

print $node->body;

I haven't tested this out though.