Using contemplate to output the body of a node
adammassey - March 6, 2007 - 12:11
| Project: | Content Templates (Contemplate) |
| Version: | 5.x-1.1 |
| Component: | Miscellaneous |
| Category: | support request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Forgive me if the answer to this exists elsewhere, I've had a search and can't find anything - and I'm pulling my hair out over this one.
I'm using contemplate, but can't work out how to output just the contents of the body of a node. I know that <?php print $node->content['#children'] ?> prints out all the fields etc associated with a node, but my lack of PHP knowledge means I don't know how to get just the body displayed.
I'm sure I managed it when I was messing around, but can't remember what it was now I need it. Any help would save my sanity!

#1
Replying to my own question.
Found that
<?php print_r($node); ?>would output all the properties of a node object (from this posting) and from using that I saw that what I was after could be got by using<?php print $node->content['body']['#value']; ?>in my content template.#2
I need to do the same thing and also came across
<?php print $node->content['body']['#value']; ?>Yet, the problem with that is, that filters/input formats do not get applied to the content in that case.
What's the best way to only show one field of a content type/CCK and still running it through the filters?
#3
I'm looking into this right now, attempting to use node_prepare results in an error. Will post the solution when I find it.
#4
Ah, all becomes clear with a little research.
Contemplate uses a nodeapi hook to apply any defined templates, switching on the 'alter' operation for non-RSS content. The API documentation states:
So, if you go to the Display Fields tab, set all the fields you're already handling to "Hidden", all that remains is to add "print $node->content['body']['#value'];" to your template and you're good to go.
I did a quick test by adding a snippet of PHP code to a templated node, switching the node's input format from "filtered HTML" to "PHP code" worked as expected.
#5
Sorry, it's late, I meant to say: For the body, just "print $node->body" in your template - but only if you turn off all the other fields in the Display Fields tab.
Do that, and you'll get the plain (filtered as specified) body content.
#6
Thanks for the info!
I was having the same issues, but I've got a couple of problems when using your fix:
- making fields hidded seems to mean I need to reconstruct those fields in the template rather than just using their default values?
- when using the insert_view module, [view] tags aren't rendered this way, although other input filters seem to be run.
#7
I've been having a play, and I'm finding it easier to just have another text field for the body of the node, rather than the standard node body. I'm a bit worried this will lead to some kind of issue (but I don't know what), but it seems easier than hiding all the other fields, as I can still use their output.
Included [view] blocks still don't work though...
#8
The following works for me:
<div class="field field-type-text field-field-body"><div class="field-items">
<div class="field-item"><?php print $node->content['body']['#value'] ?></div>
</div>
</div>
I am not sure if the code is all needed, but it works as shown. Maybe someone else who knows more about theme formatting can comment on this.
#9
cck viewfield can help you or php code
<?php//load the view by name
$view = views_get_view('gallery_name');
//output the view
print views_build_view('embed', $view);
?>
#10
It looks like this issue has been solved, is this correct?
#11
closed due to inactivity
#12
Thanks #8, that really should be in contemplate by default. My defaults at least for the blog only showed the image and not the body, I cant imagine anyone ever wanting that, the default should be a generic sane setting that would help people like me get it close instead of having to go searching for 30min to find some solution.
Great module though :)