Wednesday, June 2, 2010

Node: Body outputs entire full node, instead of Body field

The problem is not, as the linked article here suggests, limited to Views representations of Node-body content.  The problem exists in any Node or Page template that is rendered to your website.

The problem arises from the fact that templating BOTH loads a Node, and then runs the "node-alter" routine on it - affecting the Node Body field specifically, to also include contents of CCK fields in that Node.

The problem-code
The problem arises when using this variable-call in a page-template (*.tpl.php) file:
print $node->body;
The solution-code
The solution is to replace the code above with this code instead:
print $node->content['body']['#value'];

No comments:

Post a Comment