Use theme_block() to render blocks

adshill - January 15, 2009 - 04:56
Project:Insert Block
Version:HEAD
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs review
Description

I really like this - always been a bit fan of insert view, but this is a great addition. My problem is that the block is coming out with the title on it and it is the title created by the module. Is there any way to either remove the title all together or to use the title overide in the block settings instead?

Thanks,
Adam

#1

zmove - January 20, 2009 - 20:40

Hi,

I confirm this issue and subscribe for a solution. This module don't care about the block setting for the title. Result, it shouldn't show the title when it is set as into the block configuration.

#2

Pasqualle - February 25, 2009 - 22:49
Title:How can I get rid of the title? Or change to title overide?» Change the theme function
Category:support request» bug report

The problem is that insert_block module uses its own theming function, which is unnecessary (and wrong, as it does not check the title)

line 82

$repl[] = theme('insert_block_block', $block);

should be changed to
$repl[] = theme('block', $block);

and all the theme related code can be removed..

#3

Pasqualle - February 25, 2009 - 23:47
Status:active» needs review

actually this does not help as the block setting is not loaded, so the code does not know about if the block title is set to <none> or not.

But changing to core theme_block function, enables the use of new template files

function template_preprocess_block(&$variables) {
...
  $variables['template_files'][] = 'block-'. $variables['block']->region;
  $variables['template_files'][] = 'block-'. $variables['block']->module;
  $variables['template_files'][] = 'block-'. $variables['block']->module .'-'. $variables['block']->delta;

so you can use the template by region, where you can remove the title
block-insert_block.tpl.php (based on block.tpl.php)

<div id="block-<?php print $block->module .'-'. $block->delta; ?>" class="block block-<?php print $block->module ?>">
  <div class="content">
    <?php print $block->content ?>
  </div>
</div>

attached the patch, and the patched module file..

AttachmentSize
359088_theme_block.patch 1.88 KB
insert_block.module.txt 3.85 KB

#4

Pasqualle - February 25, 2009 - 23:49
Category:bug report» feature request

#5

dboulet - May 21, 2009 - 19:52
Title:Change the theme function» Use theme_block() to render blocks
Version:6.x-1.x-dev» HEAD

Thanks Pasqualle for the code, it was just what I was looking for. Unfortunately, the patch provided in comment #3 didn't work for me, so I've included a new one, rolled against HEAD.

I've also added a database call which fetches the block title, and then erases it if it is set to <none>.

AttachmentSize
insert_block_359088_theme_block.patch 2.18 KB

#6

Pasqualle - May 22, 2009 - 02:45

instead of additional db query I would prefer an additional parameter, to show or hide the title. In most cases you want to hide the block title if you put it into a template or node, but you want to show the block title if you put that block into a region.. So those should be 2 different settings..

like

[block:module=delta=hide_title]
[block:profile=0=TRUE]

This way the functionality of insert_view and insert_block would be the same as in the quicktabs module..

#7

ron_mahon - September 4, 2009 - 13:32

Great Code But what I really need is a way to show one part of a menu (block) expanded!
Any thoughts on this?
Regards
Ron

 
 

Drupal is a registered trademark of Dries Buytaert.