Override the theme to show the entire node
Rosamunda - January 8, 2007 - 14:18
| Project: | Node As Block |
| Version: | 6.x-1.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Jump to:
Description
Hello there!
I wonder -as my programming skills are pretty scarce-, how could I override the theme function.
I need to show a webform as a block (using the webform module), but I have to show the entire form there.
Is there a way (maybe as a feature wishlist) to control each individual block content from the admin/blocks section? It would be perfect! and a lot easier :-) Or maybe when you create the block from the node, that could be an option...
Thanks in advance!!!!
Rosamunda

#1
Hi rosamunda-
You can override the theme function to do what you want, mostly by using copy and paste.
Here's the current theme function:
<?php
/*** Themeing ***/
function theme_nodeasblock($node) {
// return an array with 'subject' and 'content
if (node_access('update', $node->nid)) {
$node->links['nodeasblock_edit'] = array (
'title' => t('Edit'),
'href' => 'node/'.$node->nid.'/edit',
);
}
$content = node_view($node, true, true, false);
return array('subject' => l($node->title, 'node/' . $node->nid),
'content' => $content);
}
?>
All you would have to do is change on line:
<?php
$content = node_view($node, true, true, false);
?>
to
<?php$content = node_view($node, false, true, false);
?>
For the reasons why this would work, see
http://api.drupal.org/api/4.7/function/node_view
You can actually just cut and paste the following function into your template.php and it should work. (leave out the <?php and ?> tags)
<?php
/*** Themeing ***/
function phptemplate_nodeasblock($node) {
// return an array with 'subject' and 'content
if (node_access('update', $node->nid)) {
$node->links['nodeasblock_edit'] = array (
'title' => t('Edit'),
'href' => 'node/'.$node->nid.'/edit',
);
}
$content = node_view($node, false, true, false);
return array('subject' => l($node->title, 'node/' . $node->nid),
'content' => $content);
}
?>
I like your suggestion about controlling the the fulltext vs. teaser vs. a set of specific fields (for CCK) types. I'll see what I can do to integrate that. There are some similar requests in the issue queue, and perhaps I can roll them all into a single upgrade.
Good luck and thanks for your interest in this module. Feel free to re-open this issue if you need support.
-Mark
#2
Gee thanks Mark!!!!!
That was terrific! Works like a charm!!!!!!!
Thanks you VERY VERY much!!!!!!!!
And yeah... I LOVE this module!
Rosamunda
#3
how do i do this for a 5.x install?
I have a webform that i'd like to display on certain pages as a block. can't seem to do it.
I do the node_load for the webform node and the contents of the node show up, but not the form fields.
Thanks.
#4
It's basically the same:
<?php
function phptemplate_nodeasblock($node) {
// return an array with 'subject' and 'content
$node = node_prepare($node, true);
$content = node_view($node, false, true, true);
//$content = $node->teaser; // this might be better
return array('subject' => l($node->title, 'node/' . $node->nid),
'content' => $content);
}
?>
I should probably put this in the README, as it is such a common request.
#5
As an alternative to changing or overriding the module's functions, the following (5.x) snippet seems to display the whole (form-rendered) node when included in a block:
<?php
$node = node_load(62);
print node_view($node, false, true, true);
?>
... where 62 is the ID of the node you want.
I'd welcome comments from a more experienced Drupal developer about how appropriate it is to call node_view flat out like that...
#6
I pasted the code in my PHPTemplate and it works wonderful (Drupal 5.2). However I would very much like to limit the height of the block. Now this is supposed to be simple CSS, but I am confused WHERE I should give in the height. Which CSS file, or is it in block.tpl or?
The reason: I show videos on my site and in a block next to the video there is supposed to be a block with a transcript of the video. This block should have a scroll function (which comes when I limit its height and there is excess content) otherwise the viewers would have to scroll down the entire page and the video would disappear.
Many thanks,
Theo Richel
#7
The block will have an id, something like 'block-block-4'. Using that example you could add to style.css (at the end)
#block-block-4 {height: 100px;
}
#8
For D6, it should this instead.
function phptemplate_nodeasblock($node) {
// Get an HTML representation of the themed node.
// node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
$content = node_view($node, FALSE, TRUE, TRUE);
// If the user has permissions to edit the node, then add a link.
if (node_access('update', $node)) {
$content .= '<div class="nodeasblock-edit-link">'. l('['. t('edit') .']', 'node/'. $node->nid .'/edit', array("title" => t("Edit"))) .'</div>';
}
return $content;
}
#9
This is a great module and thanks for the D6 template code!