Theming the Drupal Tray module in Drupal 6
Last updated on
30 April 2025
The Tray module comes with three theming functions you can use to change the appearance of the Tray. With these functions you can :
- Change the HTML tags used to display the tray(The tray makes use of a ul and children li by default).
- Change the display of handle and full modes for the blocks.
- Theme the block content inside the Tray.
Theming the Tray
<?php
/**
* Theme function for the tray display
*/
function theme_tray_display(){
//Update the 'blocks' DB table with the blocks currently exported by modules.
_block_rehash();
//get a list of blocks in the tray region
$blocks = block_list('tray');
$output = '<div id="tray-tray">';
$output .= '<ul class="tray-main">';
foreach($blocks as $block){
if ($block->module && ($block->delta || $block->delta === 0)) {
$block_name = $block->module .'_'. $block->delta;
}
$display_type = variable_get('tray_display_type_'.$block_name , 'handle');
if($display_type == 'full'){
$output .= theme('tray_block_full',$block);
} else {
$output .= theme('tray_block_handle',$block);
}
}
$output .= '</ul>';
$output .='</div>'; //end tray-tray
return $output;
}
?>
Theming Blocks in Handle mode
<?php
/**
* Theme function for blocks inside the tray
*/
function theme_tray_block_handle($block){
$output = '<li class="tray-item" id="tray-item-' .$block->bid. '">';
$output .= '<a href="#" title="' .$block->subject. '" class="tray-item-handle">' .t('Open'). '</a>';
$output .= '<div class="tray-item-block">';
$output .= '<div class="tray-item-controls">';
$output .= $block->subject;
$output .= '<ul>';
$output .= '<li><a href="#" class="tray-item-minimize" title="'.t('Click here to minimize this window').'">'.t('Minimize').'</a></li>';
$output .= '<li><a href="#" class="tray-item-close" title="'.t('Click here to close this window').'">'.t('Close').'</a></li>';
$output .= '</ul>';
$output .= '</div>';
$output .= '<div class="tray-item-content">';
$output .= $block->content;
$output .= '</div>';
$output .= '</div>';
$output .= '</li>';
return $output;
}
?>
You can replace t('Open') here by $block->subject if you want the title of the block to appear in the tray instead of "Open". We used open by default because sometimes block titles can get very long.
Theming Blocks in Full mode
<?php
/**
* Theme function for blocks inside the tray
*/
function theme_tray_block_full($block){
$output = '<li class="tray-item tray-item-full" id="tray-item-' .$block->bid. '">';
$output .= $block->content;
$output .= '</li>';
return $output;
}
?>
Help improve this page
Page status: Not set
You can:
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion