what is the best way to display a node body in a view?

I tried creating a block view
and setting field to "node: body"

but it my view it displays the node title, node post info along with node body

do i have to create a node.tpl file just to display my node body only in my block view?

in short i want to do this:

(block view)
* first few lines of node body only
* first few lines of node body only
* first few lines of node body only

Comments

imrook’s picture

Is your view type set to "List" or "Table"? If it is set to Full Node or Teaser, then you will get the title, posting information and all that good stuff. I know 'cause I just tested this. I thought the views module used to yell at you if you tried to choose fields with a non-list or table view type, but I could just be crazy. At any rate, try a list view with Node: body as your only field and you should be very close to what you want.

mz906’s picture

view type is list, and field is "node:body" but block view is still printing everything i.e. title, body

tisho-1’s picture

mz906, did you figure out what the problem was?

I suspect that I am having the same issue as you do, but searching for it in drupal.org did not provide much topics beside this one, so I am guessing it has to be something from either my configuration, or a contrib module that I am using...

beautifulmind’s picture

Well, its not a big deal to display the body of the node in the block, but the point is how would you extract partial text from the body field and display it.
I tried following block view:

$view = new view;
$view->name = 'block_test';
$view->description = 'This view is added for testing purpose only';
$view->tag = 'Test Block';
$view->view_php = '';
$view->base_table = 'node';
$view->is_cacheable = FALSE;
$view->api_version = 2;
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */
$handler = $view->new_display('default', 'Defaults', 'default');
$handler->override_option('fields', array(
  'body' => array(
    'id' => 'body',
    'table' => 'node_revisions',
    'field' => 'body',
  ),
));
$handler->override_option('access', array(
  'type' => 'none',
  'role' => array(),
  'perm' => '',
));
$handler = $view->new_display('block', 'Block', 'block_1');
$handler->override_option('fields', array(
  'body' => array(
    'label' => '',
    'exclude' => 0,
    'id' => 'body',
    'table' => 'node_revisions',
    'field' => 'body',
    'override' => array(
      'button' => 'Use default',
    ),
    'relationship' => 'none',
  ),
));
$handler->override_option('title', 'Recents');
$handler->override_option('use_ajax', TRUE);
$handler->override_option('use_more', 1);
$handler->override_option('row_options', array(
  'inline' => array(
    'body' => 'body',
  ),
  'separator' => '',
));

Make changes as and where you need!!

:)

Beautifulmind
Know more

Regards.
🪷 Beautifulmind