views:

33

answers:

3

Given a $node, I'm trying to decide between the following two ways of outputting that $node.

either

$output = theme('node', $node);

or

node_build_content($node);
$output = drupal_render($node->content);

They both seem to give similar results, but is there something I should consider before I choose one way over the other?

+1  A: 

First is recommend as it is passed via theme.

Nikit
+2  A: 

Your output is similar if there are no other modules and themes altering the output via the theme layer.

But! If you bypass the theme layer, you'll probably start experiencing unexpected behaviour when you install modules or themes and change config settings that use the theme layer to alter the node's output.

In short, by bypassing the theme layer, you're building error into your application. These error are likely to occur after you hand your application over to someone (a client perhaps) who starts changing settings in admin/

See the decorator pattern if you're interested. Drupal uses this extensively.

http://en.wikipedia.org/wiki/Decorator_pattern

Rimian
A: 

The solution that worked here was a combination of both of these techniques. Just using

theme('node', $node);

doesn't seem to work with out the help of

node_build_content($node);

Here is the result of an example only using theme('node', $node);

alt text

But if we first do node_build_content($node); prior to handling the $node to the theme function, you can see that the form button is also rendered.

alt text

Therefore, the real solution is:

node_build_content($node);
$output = them('node', $node);
DKinzer

related questions