I don't know why i can't seem to find this, even after doing print_r($node) - i can't seem to trace the variable i need to output the default node body.

When i do print $body or $node->body it outputs all the custom fields in addition to the body field. My brain has stopped working.

Comments

pshadow’s picture

I'm trying to find the same thing. Was hoping by moving CCK field from text to using the default body field in Drupal 5 I'd be able to use body and teasers, but print $teaser doesn't work nor does $print body_filter, and $content and $body print all the cck fields. Anyone able to print just the Body and Teaser out of the DB?

pshadow’s picture

Can anyone confirm if this is even possible? Or if going the old route of text.module for CCK body is still the most flexible solution? thanks.

luyendao’s picture

This isn't so much a solution, as a work around - and it doesn't give me the exact control i wanted (in a sense).

I ended up re-creating my CCK node, and removing the label for "Body" - and created my own custom body field. I then used the 'contemplate' module to output all the fields i wanted for teaser and body, that gets spit out in $content in node.tlp.php - then i modified node.tlp.php with a few if statements to make sure other node types weren't affected.

I'm not sure if it's the most elegant way, but it works - the longest part was just going through the 'contemplate' variables, and outputting each one 1 by 1, to get clean output and write clean xhtml.

Hope it helps.

wolfderby’s picture

Theme teaser to look different than full node.

Control output of teaser and control output of node:

http://drupal.org/node/53464

John Hwang’s picture

I think it's a bug that $body displays all the other fields of the content type.

My fix is to do:

print $node->content['body']['#value']

This is dumb though, because when you install the Devel module and look at the "Devel load" or "Devel render" the they show the body variable only contains the content of the "body" field...

kickn’s picture

does anyone know if this is going to be fixed?

MacRonin’s picture

Thanks for the Hack/work around. This was starting to drive me crazy.

I figured I was just doing something stupid since its just 5:30 AM and I needed sleep. Disappointed to see its still not fixed (Drupal 5.1 and CCK 1.4), but glad its not just me. The field list still shows the Body field to be $body_filter but that didn't work, and $content & $body give you the CCK fields also.

-------------------
http://www.PrivacyDigest.com/ News from the Privacy Front
http://www.SunflowerChildren.org/ Helping children around the world

kiev1.org’s picture

The same problem - field body_filter! And it to remove it is impossible and to deduce it in a template in any way it is impossible!

markhope’s picture

Is it safe to use #value like your example?
See: http://drupal.org/node/86104#comment-212905

What about this instead:

	print check_markup($node->content['body']['#value']); //for rich text content
	print check_plain($node->content['body']['#value']); //for plain text
yeeloon’s picture

bookmarking!

lucassouza1’s picture

It works to me!

yhager’s picture

Took me a while to find out how to do this though. If you remove the label for the body field in your content type, the body field will not be presented in node edit or view (which means you can use your own body field).

Go to admin/content/types/ and remove the text under "Body field label:".

zeropaper’s picture

This the best (and cleanest) solution as body_filter is not a CCK field.

codenamerhubarb’s picture

Go to admin/content/types/ and remove the text under "Body field label:".

This didn't work for me so I commented out the following lines (lines 211 and 212) in "/modules/blog/blog.module"...

  $form['body_filter']['body'] = array('#type' => 'textarea', '#title' => check_plain($type->body_label), '#default_value' => $node->body, '#rows' => 20, '#required' => TRUE);
  $form['body_filter']['filter'] = filter_form($node->format);

Then simply make your own body field using CCK. Problem solved.

-------------------------------
My Drupal site: Download a Book.

robertlove’s picture

I had exactly this issue today whilst demonstrating CCK to a colleague. I ended up doing print_r($node) to find the body content and after finding it using print $node->content['body']['#value'], just as you guys have.

However, I told my colleague we'll do it this way for now but I'll find the right way because there is no way Drupal would not provide a way to easily access body content - it's way too smart for that!

Famous last words I suppose :(

Does anyone know if this is still the case with Drupal 6.x???

Cheers

ericpugh’s picture

			<?php  print $node->content['body']['#value']; ?>

Yes, this is still working for me in D6.

blasthaus’s picture

is it possible? I have a client who will be posting content types where they will be wysiwyg entering content that includes images. I simply want to wrap the images with a sliding doors type of css treatment. any techniques would be of huge help.

yhager’s picture

CSS is your only way to theme images inline. With a bit of javascript, you can do quite a lot.

blasthaus’s picture

thanks, i have given up on this after trying to use template.php and str_replace() on the image tags in $element['body']['#value'] just to prepend some divs for each image. i'm overriding theme_markup function but its not working in D6. Maybe this function happens before views and that's why. The divs don't show up even though i get a return value that the str_replace happened x-number of times. Here's the non-working attempt:

function yourtheme_markup($element) {
if (strpos($element['body']['#value'], '<img')) {
str_replace('<img', '<div class="tr"></div><div class="tl"></div><img', $element['body']['#value'], $num);
echo $num;
}
  return (isset($element['#value']) ? $element['#value'] : '') . (isset($element['#children']) ? $element['#children'] : '');
}
yhager’s picture

This is really a bad way to look at the situation. If you need image formatting, then create a field and theme it's display in the right place. There are also filters that help you locate the image inline the text by using some code in the text (no links, sorry). You can use that approach and create the image tag correctly in the filter code, instead of trying to manipulate strings at the end of the stack.

PS - your code doesn't work because you ignore the return value from str_replace, but I do not recommend investing that path any much more.

blasthaus’s picture

thanks a lot, yea i knew that was a bad way to approach it. i have yet to get this detail figured out, but after looking at the Insert module (formerly Filefield Insert) http://drupal.org/project/insert I'm hoping to get at the images in a more graceful way.

Thanks for your help.

-wil