I'd just like to print out the body of a specific node (no title or other fields). Am I doing this right?
I can't seem to find the answer in any of the Drupal docs.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
Looking with the Devel module to the structure of a loaded node, I notice that "body" contains the following values:
The first array index is the language ID for the language set for the node; it could be also LANGUAGE_NONE (the string "und") for nodes for which the language is set to "neutral." That array index contains an array with the following indexes:
In the node I used as example, if you try accessing
$node->body['und']['value'], you would access an undefined value. You should use
$node->language to know the language set for the node; you code should be similar to the following one:
$node = node_load(127); $body = $node->body[$node->language]['value'];
As for printing the body content, the "body" field contains the text before the input filter is applied; you should use code similar to the following one, to print the "body" field:
$node = node_load(127); $language = $node->language; print check_markup($node->body[$language]['value'], $node->body[$language]['format'], $language);
$node = node_load(127); print $node->body;
Please, note, this outputs just the content of the Body textarea as input in the node form.
To output the fully themed node without title and links would require a separate template file, its introduction via a preprocess function, and a call to
print theme('node', $node);