Hi -

I have a secondary menu set up which appears as a block in a particular region. The block's title is 'csr-secondary'. From what I have read I assume that to override the default block.tpl.php template I should copy it into my theme folder and rename it 'block--csr-secondary.tpl.php' but this is not working!

Can anyone please put me right?

Also, in the past when learning a new open source platform/product I have often advertised for an expert who would be willing to provide a one-to-one tutorial via skype for a fee (via paypal). Sometimes it is just so much more cost effective to pay to have a direct Q/A session when the problems are more conceptual rather than routine. Would this be an appropriate place to place such an advert? If not, where?

Many thanks

Comments

pixelite’s picture

If you've created a custom block (for example, with an ID of block-block-1), then the template name should be block--block--1.tpl.php.

sectornitad’s picture

thank you for your reply - but how the heck does one find out which block number it is????!!!!

There is nothing apparent in the 'create block' screen of the admin console which lets one know which number the system is providing it..

thanks again..

pixelite’s picture

When you're editing a custom block, the path will be something like '/admin/structure/block/manage/block/12/configure'. For this URL, you would use block--block--12.tpl.php. The number 12 is called the block's delta. You can also view the source of the page where you block appears (or use Firebug to inspect) and look for the ID given to the block.

birdonwire’s picture

i tried that -- in the block file name but it's not working , i read in the forum that it's a bug and there's a patch for it

jeffschuler’s picture

manmohandream’s picture

Hello,
if you are overriding block.tpl.php in drupal 7 use below given format:
block--block--user_register.tpl (use this if block has some name instead of id)
block--block--6.tpl (use this if block has id)

In case block is coming from any module like block from form block module use following format:
block--formblock--user_register.tpl

This has worked for me.
Clear all cache and save the theme after uploading the template.

Thanks

manmohandream’s picture

This is the default block.tpl.php in drupal 7
/*--------------------default block.tpl.php----------------------*/

<div id="block-<?php print $block->module . '-' . $block->delta; ?>" class="<?php print $classes; ?> " <?php print $attributes; ?>>
<?php print render($title_prefix); ?>
<?php if ($block->subject): ?>
  <h2><?php print $block->subject ?></h2>
<?php endif;?>
<?php print render($title_suffix); ?>

<div class="content"<?php print $content_attributes; ?>>
<?php print $content ?>
</div>
</div>

Thanks

vraall’s picture

Problem: Unable to Override the drupal 7 Block
Action Done:
I have tried to override the block which has ID "1" and constructed the filename as "block--block--1.tpl.php" and placed in "sites/all/themes/theme-name/templates/block--block--1.tpl.php"

I have placed the following in "page.tpl.php" to check whether block has been customized or not. ( location of page.tpl is "sites/all/themes/theme-name/templates/page.tpl.php"

The Code is:

$block = block_load('block', 1);
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
$output = drupal_render($build);
print "<pre>";
print_r($output);
exit;
Antz’s picture

Pixelite, this helped me a lot. It shouldn't have taken me this long to find this answer! Thank you!

fszakka’s picture

I just had an issue with theming specific blocks in a region. what i did to solve is was the following:

1. i added a block.tpl.php which i found from the module/block folder and copied it to my template directory.

2. i then copied the content of the block.tpl.php to an empty file and i renamed that file ex
block--sidebar_second.tpl.php where [sidebar_second] is the name of the region i had given it in my
.info file

3. I then made changes to the new file as i see fit.

4 I cleared all caches.

and it worked.

regions[sidebar_second] = Sidebar second

the catch here is that the naming in d7 is as follows block--[region name as in info file].tpl.php

stoomagoo’s picture

Greetings all,

So the naming convention for block template files (to override block.tpl.php) is still unclear to me, as I found what seems like unexpected behavior. Any help with my confusion would be greatly appreciated.

I created a custom (coded) block module, but could not get the naming convention to work for the template.

The conventions described above (in this post), and here:

http://drupal.org/node/104319
http://drupal.org/node/1323980

do not appear to work? or don't work for a block module?

The html output for the block's main DIV is:

which does not include my module name. (Is this the convention for custom block modules?)

Also the value of $block->module is:

systemblock-system-main

What eventually worked (after trying a large number of different file names) is:

block--system.tpl.php

Could anyone help explain the naming convention this is following?

And do all block modules have use the same template file then?

Many thanks in advance for any insights. :)

Best
Stuart

anou’s picture

For blocks made by views

Here's the html of my block :

<section class="block block-views contextual-links-region" id="block-views-VIEWSNAME-block-1">
<h2 class="block-title">My block title</h2>
<div class="content"><div class="view-content">[... SOME CODE ...]</div></div> 
</section>

The ID is in my example : "block-views-VIEWSNAME-block-1"

And the tpl is : block--views--VIEWSNAME-block-1.tpl.php

Et voilà.

David THOMAS
http://www.smol.org

leewoodman’s picture

thanks for this...exactly what i needed

Lee

bingorabbit’s picture

Very helpful, that's exactly when I needed..