I couldn't do what I wanted for this, so I had to do the following to workaround it:

block-views.tpl.php

<?php
// $Id: block.tpl.php,v 1.1.2.2.2.4 2009/01/16 21:53:32 tombigel Exp $

/**
* @file block.tpl.php
*
* Theme implementation to display a block.
*
* Available variables:
* - $block->subject: Block title.
* - $block->content: Block content.
* - $block->module: Module that generated the block.
* - $block->delta: This is a numeric id connected to each module.
* - $block->region: The block region embedding the current block.
*
* Helper variables:
* - $block_zebra: Outputs 'odd' and 'even' dependent on each block region.
* - $zebra: Same output as $block_zebra but independent of any block region.
* - $block_id: Counter dependent on each block region.
* - $id: Same output as $block_id but independent of any block region.
* - $is_front: Flags true when presented in the front page.
* - $logged_in: Flags true when the current user is a logged-in member.
* - $is_admin: Flags true when the current user is an administrator.
*
* Tendu Specific:
* - $block_region_placement: Outputs 'block-first and 'block-last' to the first and the last blocks on each block region.
*
* Suport for "block-class" and "block-theme" modules (Not included in the theme):
* - $blocktheme: Blocktheme's machine readable block name.
* - block_class($block): Block classes defined in admin/build/block
*
* @see template_preprocess()
* @see template_preprocess_block()
*/
// Here we override specific blocks based on their name and delta, more specifically by which view provides the block
// There is a limitation in Views module which keeps one from doing block-views-[VIEWNAME].tpl.php for all blocks from a particular view.
// As a workaround we simply check the VIEWNAME here to override the template as needed.
?>
<?php // grab the block->delta and strip off the number at the end
$blockdelta = substr($block->delta, 0, (strrpos($block->delta, "_")));
// create a blockname to be used for our switch
$blockname = "block-{$block->module}-{$blockdelta}";
// this switch uses any views block's id (without the numerical value that is at the end)
switch ($blockname):

  case "uc_products-block": ?>
  <div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="block block-<?php print $block->module ?> <?php print $block_region_placement ?> block-<?php print $block_zebra ?> <?php if ($blocktheme != '') print $blocktheme; if (function_exists(block_class)) print block_class($block); ?>">
  <?php if ($block->subject): ?>
    <h2><?php print $block->subject ?></h2>
  <?php endif;?>

    <?php print $block->content ?>
  </div><?php
  break;

  default: ?>
  <div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="block block-<?php print $block->module ?> <?php print $block_region_placement ?> block-<?php print $block_zebra ?> <?php if ($blocktheme != '') print $blocktheme; if (function_exists(block_class)) print block_class($block); ?>">
  <?php if ($block->subject): ?>
    <h2><?php print $block->subject ?></h2>
  <?php endif;?>

    <div class="content">
      <?php print $block->content ?>
    </div>
  </div><?php
  break;

endswitch;
?>

Comments

dawehner’s picture

Status: Active » Needs work

Thats not how you should implement this! Use hook_preprocess_block and add template suggestions.

<?php
function hook_preprocess_block(&$vars) {
  list($name, $display-id) = $vars['block']->delta;
  $vars['template_suggestions'][] = 'block-'. $variables['block']->module .'-'. $name;
}
?>
nicholas.alipaz’s picture

Thanks for the correction. I still think this should be added as an option in views.

dawehner’s picture

My code will not work..

  list($name, $display-id) = explode('-', $vars['block']->delta);
merlinofchaos’s picture

Just an FYI, this will only work if the view name, the dash, and the display ID all add up to 32 characters or less. If longer, the delta becomes an MD5 hash because the delta isl imited to 32 characters.

dawehner’s picture

Do you know a way to fix this?

nicholas.alipaz’s picture

I am using this in my template.php:

/**
 * template_preprocess_block
 * - Add block-views-[view_namespace].tpl.php template suggestions
 * -- this allows us to style all blocks of a specific view
 */
function mytheme_preprocess_block(&$vars) {
  $blockdelta = substr($vars['block']->delta, 0, (strrpos($vars['block']->delta, "-block_")));
  $vars['template_suggestions'][] = 'block-views-'. $blockdelta;
}

There may be a better way however. Also, one needs to check for the MD5 hash if it is too long as merlinofchaos mentioned.

merlinofchaos’s picture

I believe anything placed inthe $block array returned by hook_block() will make it to the template. We can put data in there, and use hook_preprocess_block() to add suggestions based on that data, perhaps.

nyl_auster’s picture

Hello
Is there something new about that ? templates block name with md5 happen very often if you work on a big site with very descriptive name for the blocks.
Is there a way, playin with preprocess, to pass to the preprocess_block the name of the view ?

nyl_auster’s picture

real name of the views is registered in the variable table
here is the snippet code i use to add a suggestion template for the realname of the views (name + display-id) for the blocks, if delta became a md5.
This go in a themename_preprocess_block() :

  $block = $vars['block'];
  $chars_delta = strlen($block->delta);
  // don't do anything if this block is not from views module or if delta < 32 chararacters
  // because md5 is always 32
  if ($block->module == 'views' && $chars_delta >= '32') {
     //get from variable table the hashes and their corresponding views name, in an associative array
     $hashes = variable_get('views_block_hashes', '');
    // add a nice new template suggestion if this delta is a hash
    if(isset($hashes[$block->delta])) {
       $vars['block_id'] = 'block-'. $block->module .'-'. $hashes[$block->delta];
       $vars['template_files'][] = $vars['block_id'];
    }
  }
  else {  
    // just set the normal block id for css
    $vars['block_id'] = 'block-'. $block->module .'-'. $block->delta;
  }
dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new1.35 KB

Here is a patch

dawehner’s picture

Status: Needs review » Needs work

doah

dawehner’s picture

Version: 6.x-2.x-dev » 7.x-3.x-dev
Status: Needs work » Patch (to be ported)

It works find on 6.x-3.x. Needs porting to d7.

nicholas.alipaz’s picture

tested and works for me. 6.x-3.x-dev

phoenix’s picture

Hi

I encountered the same problem to style a specific views block. But the weirdest thing is that the template should be in the template suggestions of core drupal 7. Check here: http://drupal.org/node/1089656

block--[region|[module|--delta]].tpl.php

But it's not working for me. Even when using some code from above to add the template suggestion in theme_preprocess_block, it doesn't work.
Any ideas for views 7.x-3.0-beta3 on drupal 7?

dgastudio’s picture

sub

paulgemini’s picture

subing

dawehner’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new1.38 KB

Here is a patch for d7.

It would be great if some people could test it.

dawehner’s picture

+++ b/views.moduleundefined
@@ -276,6 +276,20 @@ function views_preprocess_comment(&$vars) {
+function views_preprocess_block($vars) {
+  if (!empty($vars['block']->view)) {
+    $vars['view'] = &$vars['block']->view;
+    $vars['theme_hook_suggestions'][] = 'block-view-' . $vars['view']->name;
+    if(!empty($vars['view']->current_display)) {
+      $vars['theme_hook_suggestions'][] = 'block-view-' . $vars['view']->name . '-' . $vars['view']->current_display;
+    }
+  }
+}
+
 /*
  * Implement hook_permission().
  */

Does this really work? Isn't the preprocess runned after the lifetime of the view-object?

tim.plunkett’s picture

Triggering the testbot.

Status: Needs review » Needs work

The last submitted patch, views-631418-block-templates.patch, failed testing.

epiphanydigital’s picture

This works out of the box.
Just name the tpl file you need as follows:

block--views--view_machine_name.tpl.php

amuhlou’s picture

It does work out of the box, but the underscores should be replaced with single hyphens -
block--views--view-machine-name.tpl.php