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

Comments

Status:Active» Closed (fixed)

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

Gee thanks Mark!!!!!
That was terrific! Works like a charm!!!!!!!
Thanks you VERY VERY much!!!!!!!!
And yeah... I LOVE this module!

Rosamunda

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.

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.

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...

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

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;
}

Version:4.7.x-1.x-dev» 6.x-1.x-dev

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;
}

This is a great module and thanks for the D6 template code!

Hi,

I'm quiet new to Drupal and would like to use this.
i'm trying to incorporate this but i'm not achieving.
in which file do i need to set those changes?

Kind regards

Kurt

Is this module no longer being maintained? I have the same question as the last poster: using the latest V6 version and dev version of this module, I can't figure out how to allow the full node (rather than just the teaser) to be accepted. Thank you.

Status:Closed (fixed)» Active

Status:Active» Needs review

Hi,

With some additional stuff to comment#8 it worked on my project and displayed full node instead of teaser.

Just add this function to your template.php file:

<?php
function phptemplate_nodeasblock($node) {
 
// undo changes that nodeasblock module made in nodeasblock_block_content() @ nodeasblock.module
   
$node->body = $node->teaser;
    unset(
$node->build_mode, $node->readmore, $node->content);
 
// Get an HTML representation of the themed node.
  // node_view($node, $teaser = FALSE, $page = FALSE, $links = TRUE)
 
$content = node_view($node, false, true, false);
 
// 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;
}
?>

Please provide some feedback if it works on your projects.

Hi Daugis,

You can also do this:

<?php
function THEME_NAME_preprocess_nodeasblock(&$vars) {
 
$node = $vars['node'];
 
$node = node_load($node->nid, NULL, TRUE);
 
$node->build_mode = NODE_BUILD_NORMAL;
 
$node = node_build_content($node, FALSE, TRUE);
 
// If the user has permissions to edit the node, then add a link.
 
if (node_access('update', $node)) {
   
$vars['edit_link'] =  l('['. t('edit') .']', 'node/'. $node->nid .'/edit', array("title" => t("Edit")));
  }
 
$vars['content'] = drupal_render($node->content);
}
?>