I'm doing some testing and learning how Drupal works.

I know there are other ways to do this that involve modules such as related content however I want to use php code in the body of one node to display the content of another node. I have done some searches but can't find anything so basic.

Thanks

Comments

meric’s picture

node_view() and node_load() will do that..

if you want to load a whole node into another node you can do so by adding something like this in the node's body:

//load a node to this node..

//for example, the node ID I want to load is 15.
$node = node_load(15);

//now we have an object representing the node. Let's render its HTML via node_view()..
print node_view($node);

//done!

node_load() requires node ID as the parameter, or an array of its properties like: array('name' => 'MyFirstNode')

node_view() renders an HTML output, which requires a node object as its parameter.

Hope this helps.

j0hn-smith’s picture

Yes it does, a lot.

I'd found node_view() but didn't know how to use it.

Many thanks

aharown07’s picture

Who'd have thought that was so easy... now maybe someone can tell me how to make it display in a little block, say off to the left? Haven't tried this yet, but woud it work to go something like this...

print <div class="something">;
print node_view($node);
print </div>

And then put some css in my template's css file for "something"?

Or am I way way off?

cegri’s picture

This was most helpful.

I'm also trying to display the comments of a node. Is there a function like comment.view($node)?