I am trying to include nodes into blocks. Here's are the attempts and approaches:

1) Attach a node into a block using node_load (http://api.drupal.org/api/5/function/node_view).

<?php
$node = node_load(11); // Change to whatever the nid of your node is
print node_view($node, FALSE, FALSE, FALSE);
?>

This works perfectly but is showing the title of the node in the block. How can it be removed?

2) Using another approach:

<?php
// We save and restore the real path for the page
$q = $_GET['q'];
// Change event to the path you want, this is the part after q= (or after the base path if you have clean URLs enabled)
// The call to drupal_get_normal() allows for using path aliases.
$_GET['q'] = drupal_get_normal_path('contact');
// Get and print the output for just the content associated with the path
// If you see the complete page within a page it means the path callback is probably calling theme('page', ....)
print menu_execute_active_handler();
// Restore the real path for the page
$_GET['q'] = $q;
?>

While this works for attaching a node into another node, it doesn't work for attaching a node into a block. Instead, I get the default node text you see on a clean Drupal install.

3) Installing nodeasablock module. I haven't tested this approach yet.

Any ideas? The outcome of this will be documented in the handbook :)

Comments

sadnan’s picture

Why donot u extract body of your node (if it's standard node like page or book) by using $node->body and use ur view command?

kingandy’s picture

On investigation, this seems to lead to complications when you're using PHP code in your nodes.

I'm assuming, in order to use $node->body instead of node_view(), you'd do something like this:

$node = node_load(11); // Change to whatever the nid of your node is
print $node->body;

The problem here is that 'print' doesn't execute any PHP code that's in the node body - it just sends it straight to the browser. Since the browser is not on speaking terms with PHP, it comes through as so much garbage.

A slightly sneaky but enormously easy way to avoid displaying the node title is to lie to node_view, and tell it that "the node is being displayed by itself as a page":

$node = node_load(11); // Change to whatever the nid of your node is
print node_view($node, FALSE, TRUE, FALSE);

The third variable here - TRUE - is the $page variable, which is passed right through to whatever node renderer is ultimately used for the page. Most node renderers (such as the appropriate .tpl.php file, in the Phptemplate theme system) choose not to display the node title if they're rendering a $page, since the active node title is usually already rendered by the main theme.

++Andy
Developing Drupal websites for Livelink New Media since 2008

sadnan’s picture

Why donot u extract body of your node (if it's standard node like page or book) by using $node->body and use ur view command?

stBorchert’s picture

Have you tried to create a block view?
Go to admin/build/view and add a new view. Then check "Provide Block" (in section "Block") select "Full Node" and set "Nodes per Block" to 1.
Then select your filter and save the view. It should work.

hth,

Stefan

BioALIEN’s picture

Thanks for the feedback. I forgot to mention a few of the other possibilities like using Views as mentioned above.

All in all, I went for Node As Block (http://drupal.org/project/nodeasblock) as this perfectly captures what I was intending to do. It allows an admin to enable users to post node contents into blocks. It still needs some enhancements, but major kudos to the developers.

---
Dee
iScene Interactive :: iScene.eu