User login

Use just the body field in the view of a CCK node

This requires theming the view. Views does not know about or provide just the raw body, so you have to theme the view, load the node, and grab the body field.

In your view-....tpl.php:

<?php
 
$fullnode = node_load($node->nid);
print check_markup($fullnode->body, $fullnode->format, FALSE);
?>

THIS HAS SIGNIFICANT PERFORMANCE IMPLICATION FOR MANY NODES WITH MANY FIELDS

needs work, this kind of view field needs to be in core (there is code for this somewhere, they're calling it the "raw" node body, but I can't find the link anymore)

Some barely related conversation, and then on to the part where we hashed this out, in a back and forth that many Drupal developers have probably had with colleagues, or themselves...

dan hak 12:00
nodequeue is cool
i like it
a lot

benjamin melançon 12:00
sweet
it's still looking for some more documenting i think

dan hak 12:01
http://lc.openzuka.com/this_is_the_first_test_resource_that_isn039t_featured
you can feature with one click ( at bottom )
it changes the resource page

benjamin melançon 12:01
sweet
so you can change the view to show "the top item in this nodequeue" ?

dan hak 12:02
yep

benjamin melançon 12:02
and you don't have to have a maximum number of items in a nodequeue if you don't want?

dan hak 12:02
it filters by nodequeue item
well, I do
so that it switches
it will make it simpler for todd and them

benjamin melançon 12:03
that's fine, but if they want a history we can do that too

dan hak 12:03
word

benjamin melançon 12:04
with nodequeue my filter by a view thing probably isn't even necessary
http://agaricdesign.com/note/draft-documentation-nodequeue-2
current: http://www.logrus.com/nodequeue/readme.txt

dan hak 12:27
will this work in theming a view?
<?php
 print $node->content['body']['#value'];
?>

i guess i'm gonna find out in two secs

benjamin melançon 12:28
um, no
unless you load the node first
it'll be $view-> .. something

dan hak 12:28
well, how can i print just the body text in a themed view?
<?php
 print $view->content['body']['#value'];
?>

?
little help pls

benjamin melançon 12:29
put a print_r($view) in there...
that's pretty much my only trick

dan hak 12:30
fine!
http://lc.openzuka.com/resourcelibrary
ok it's there
help
print http://lc.openzuka.com/view/featuredresource
no print
thats the link to the view

benjamin melançon 12:32
actually i don't think print $view was what i wanted
the views theme wizard tells you the variables it provides doesn't it?

dan hak 12:33
yep
but agin, body prints the pic again

benjamin melançon 12:33
<?php
print '<pre>';
print_r(get_defined_vars());
print '</pre>';
?>

dan hak 12:33
<?php
 print $title
?>

<?php
 print $field_resource_image_fid
?>

<?php
 print $body
?>

put that in?

ok

it's there

the body is with the pic!!

you there?

benjamin melançon 12:36
um

dan hak 12:39
http://drupal.org/node/160641

benjamin melançon 12:40
You're going to have to do $fullnode = node_load($node->nid)

dan hak 12:40
did you look at the link yet?
what should I do?

benjamin melançon 12:41
starting to

the easier way is to just load the node

and then you can do it exactly as you did when theming the node

so the view should be providing you with the nid

dan hak 12:41
so add that line to the top of the view tpl?

or in template?

benjamin melançon 12:42
in the view tpl

dan hak 12:42
word

didnt work
i prolly did it wrong

benjamin melançon 12:44
is it inside php first of all?

dan hak 12:44
<?php
 
/**
 * views template to output one 'row' of a view.
 * This code was generated by the views theming wizard
 * Date: Fri, 2008-02-22 13:09
 * View: featured_resource
 *
 * Variables available:
 * $view -- the entire view object. Important parts of this object are
 *   featured_resource, .
 * $view_type -- The type of the view. Probably 'page' or 'block' but could
 *   also be 'embed' or other string passed in from a custom view creator.
 * $node -- the raw data. This is not a real node object, but will contain
 *   the nid as well as other support fields that might be necessary.
 * $count -- the current row in the view (not TOTAL but for this page) starting
 *   from 0.
 * $stripe -- 'odd' or 'even', alternating. * $title -- Display the title of the node.
 * $title_label -- The assigned label for $title
 * $body -- Display the Main Content.
 * $body_label -- The assigned label for $body
 *
 * This function goes in your views-list-featured_resource.tpl.php file
 */
 

 //now we add the stylesheet...
  drupal_add_css(path_to_theme() .'/views-list-featured_resource.css');
  $fullnode = node_load($node->nid)
 
 
?>

<?php
 print $title
?>

<?php
 print $field_resource_image_fid
?>

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

yea it is

benjamin melançon 12:45
yeah... you created the variable $fullnode
so don't you think you might want to use it?

dan hak 12:45
:|

benjamin melançon 12:45
<?php
 print $fullnode->content['body']['#value'];
?>

dan hak 12:45
<?php
 print $fullnode->content['body']['#value'];
?>

??
oh
ok
http://lc.openzuka.com/view/featuredresource
still nothin

benjamin melançon 12:51
sigh... <?php
 print_r($fullnode->content)
?>
and let's see what we have

dan hak 12:52
i added your line and it didnt change

benjamin melançon 12:53
print 'help'
and just make it print_r($fullnode)

dan hak 12:55
do it

benjamin melançon 12:55
and print_r the original $node, but it has to have an nid

dan hak 12:55
?

benjamin melançon 12:56
A. Do something to prove your changes are being noticed
reload the page
they are there

benjamin melançon 12:58
how come the body *so* doesn't look like it has a picture in it?

dan hak 12:58
it doesnt here
i dunno why

benjamin melançon 12:58
<?php
  print $node->body;
?>
?

dan hak 1:00
nope, didnt work

<?php
  print $node->body;
?>

benjamin melançon 1:00
what did it do?

dan hak 1:00
nothing

benjamin melançon 1:01
let's see the whole view tpl again

dan hak 1:02
yep

<?php
 
/**
 * views template to output one 'row' of a view.
 * This code was generated by the views theming wizard
 * Date: Fri, 2008-02-22 13:09
 * View: featured_resource
 *
 * Variables available:
 * $view -- the entire view object. Important parts of this object are
 *   featured_resource, .
 * $view_type -- The type of the view. Probably 'page' or 'block' but could
 *   also be 'embed' or other string passed in from a custom view creator.
 * $node -- the raw data. This is not a real node object, but will contain
 *   the nid as well as other support fields that might be necessary.
 * $count -- the current row in the view (not TOTAL but for this page) starting
 *   from 0.
 * $stripe -- 'odd' or 'even', alternating. * $title -- Display the title of the node.
 * $title_label -- The assigned label for $title
 * $body -- Display the Main Content.
 * $body_label -- The assigned label for $body
 *
 * This function goes in your views-list-featured_resource.tpl.php file
 */
 
  $fullnode = node_load($node->nid)
 
?>

<?php
 print $title
?>

<?php
 print $field_resource_image_fid
?>

<?php
  print check_markup($fullnode->body, $fullnode->format, FALSE);
?>

<?php
  // NOT:   print $node->body;
?>

benjamin melançon 1:05
and the output I saw before was a print_r on $node or on $fullnode?
that's the only place that could switch
because seriously, if you can see it in the print_r, you do see it when you print that piece of an object
it was on node
nope
sorry
<?php
 print_r($fullnode)
?>

work!!

benjamin melançon 1:09
ok, so print $fullnode->body really ought to work

dan hak 1:09
so it's <?php
  print $fullnode->body;
?>
??
ok

benjamin melançon 1:09
apparently

damned if i know what's going on
node_load must do things differently than what is handed to node.tpl.php
which means we should *probably* be throwing a drupal_render in there somewhere

dan hak 1:10
victory!

benjamin melançon 1:14
ok, one more thing you have to do
wrap the whole thing (well except for the print statement)
in check_markup
http://api.drupal.org/api/function/check_markup/5
like so:

dan hak 1:15
um
benjamin melançon 1:15

<?php
 print check_markup($fullnode->body, $fullnode->format, FALSE)
?>

'cause otherwise none of the input format / filtering rules will be followed

dan hak 1:16
huh?

benjamin melançon 1:17
automatic line breaks, linking, etc.

$fullnode->body is raw what is stored in the DB

dan hak 1:17
so add that line to the top somewhere?

benjamin melançon 1:17
no
replace the print $fullnode line with that

dan hak 1:18
<?php
 print $fullnode->body;
?>
??

benjamin melançon 1:18
yes, replace that with my wonderful line already
grr

dan hak 1:18
ok
god!

Resolution

To print just the body of a node, the body in the sense of a body field in a node that has other fields, place this in your view-....tpl.php file in your theme:

<?php
 
$fullnode = node_load($node->nid);
print check_markup($fullnode->body, $fullnode->format, FALSE);
?>

Searched words: 
theme view drupal body text only drupal input format apply body drupal views display raw field Drupal body field exposed to view

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You can use Markdown syntax to format and style the text. Also see Markdown Extra for tables, footnotes, and more.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img> <blockquote> <small> <h2> <h3> <h4> <h5> <h6> <sub> <sup> <p> <br> <strike> <table> <tr> <td> <thead> <th> <tbody> <tt> <output>
  • Lines and paragraphs break automatically.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.