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!
Comments
Comment #1
admmssy commentedReplying 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.Comment #2
riemann commentedI 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?
Comment #3
SubWolf commentedI'm looking into this right now, attempting to use node_prepare results in an error. Will post the solution when I find it.
Comment #4
SubWolf commentedAh, 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.
Comment #5
SubWolf commentedSorry, 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.
Comment #6
mo-seph commentedThanks 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.
Comment #7
mo-seph commentedI'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...
Comment #8
bdornbush commentedThe following works for me:
I am not sure if the
Comment #9
alxbkh commentedcck viewfield can help you or php code
Comment #10
jrglasgow commentedIt looks like this issue has been solved, is this correct?
Comment #11
jrglasgow commentedclosed due to inactivity
Comment #12
RikiB commentedThanks #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 :)