More flexibility with block title and theming
| Project: | Node Blocks |
| Version: | 6.x-1.x-dev |
| Component: | Miscellaneous |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
One reason for me to use nodeblock module is that it allows html in the block title - unlike the native Drupal blocks, which escape the title. Typically, I want to add some span tags to give some elements in the block title a different font size or color.
The downside is that now the escaped html tags appear in node and block listings, and in the edit page itself.
A nice solution would be to use a CCK field as the block title.
A simple and flexible way to do that with nodeblock would be to give the $node variable to the block template, so it can be used in theme preprocess functions for block.tpl.php.
In nodeblock.module:
<?php
function nodeblock_block($op = 'list', $delta = 0, $edit = array()) {
[..]
$block['subject'] = $node->title;
// using page arg = TRUE since we want the full content (generally speaking)
$block['content'] = node_view($node, FALSE, TRUE, TRUE);
$block['nodeblock_node'] = $node;
return $block;
}
}
?>Another solution would be to make a function theme_nodeblock_subject($node) that would by default use the node title as the subject.

#1
I found a very easy solution that requires a minimal patch.
In nodeblock.module, starting with line 121 (function nodeblock_block).
Old code:
<?php$block['subject'] = $node->title;
// using page arg = TRUE since we want the full content (generally speaking)
$block['content'] = node_view($node, FALSE, TRUE, TRUE);
?>
New code:
<?php// using page arg = TRUE since we want the full content (generally speaking)
$block['content'] = node_view($node, FALSE, TRUE, TRUE);
$block['subject'] = $node->title;
?>
Now you can manipulate $node->title in your template or theme function, using the cck fields of your choice.
It's a bit odd, yes, but it works!
#2
I think the following is more useful:
<?php$block['subject'] = $node->title;
// using page arg = TRUE since we want the full content (generally speaking)
$block['content'] = node_view($node, FALSE, TRUE, TRUE);
// let the block template know about the node data
$block['nodeblock_node'] = $node;
?>