How do I choose between theme ('node', $ node) and drupal_render ($ node & # 8594; content) for $ node programmatic output

Given $node, I'm trying to solve the following two ways to output this $ node.

or

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

or

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

Both of them seem to give similar results, but is there something I should consider before choosing one of the other's methods?

+5
source share
6 answers

Your output is similar if there are no other modules and topics that change the output through the theme layer.

But! If you bypass the theme layer, you will probably begin to experience unexpected behavior when installing modules or themes and changing configuration settings that use the theme layer to change the output of the node.

, , . , , , - (, ), admin/

, . Drupal .

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

+7

, sortof.

,

$output = node_view($node);

node_build_content, ('node', $node), hook_nodeapi('alter') hook_link().

, - node, , , , .

, $output = node_view($node, FALSE, FALSE, FALSE);, node .

node_view().

+6

drupal_render(), theme() ( #theme).

+1

Drupal 7 :

$elements = node_view($node, 'teaser');
$rendered_node = drupal_render($elements);
+1

, .

0

, , . theme('node', $node); node_build_content($node);.

, theme('node', $node);.

alt text

node_build_content($node); $node , , .

alt text

, :

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

All Articles