More flexibility with block title and theming

donquixote - August 18, 2009 - 16:13
Project:Node Blocks
Version:6.x-1.x-dev
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

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

donquixote - September 6, 2009 - 21:49

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

donquixote - October 8, 2009 - 05:02

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

 
 

Drupal is a registered trademark of Dries Buytaert.