[development] finding blocks and getting them simpler.

Earl Miles merlin at logrus.com
Mon May 15 20:29:44 UTC 2006


Khalid B wrote:
> On 5/15/06, Khalid B <kb at 2bits.com> wrote:
>> On 5/15/06, Bèr Kessels <ber at webschuur.com> wrote:
>> > Hello list,
>> >
>> > One thing that has bothered me for a long time, is how to 
>> get/find/parse
>> > blocks in a simple way.
>> >
>> > Problems are:
>> > * you need to read the code to find the "delta". Modules like views 
>> require
>> > you to hover the admin/blocks/edit links in order to find the delta.
>> > * a block returned by hook_block('view') needs casting and 
>> remodelling before
>> > I can be passed to theme_block.
>> >
>> > I addressed the last point with a helper function get_block.
>> >
>> > But that function still has the first problem above: You need to 
>> know a) the
>> > module that makes the block and b) the delta.
>> >
>> > Does anyone know a trick for this? Or did I miss an API function? 
>> Is someone
>> > working on code for this?
>> >
>> > NOTE: I am not particularly interested in a discussion to revise 
>> the core
>> > block architecture. Eventhough that might be an interesting 
>> project, I am
>> > looking for an intermediate function/api-set right now :)
>>
>> Initially, I used flexiblock to get the blocks I wanted where I want 
>> them (e.g.
>> adsense blocks),
>>
>> Later, I decided that less dependancies is better, and to do it
>> directly from core.
>>
>> In 4.7, there is the block regions stuff, which should work great
>> (more on that below).
>>
>> Like Ber and Merlin, I find myself using the delta too. In 
>> template.php, I find
>> myself doing this:
>>
>> function phptemplate_get_block($block_id) {
>>   $block = block_block('view', $block_id);
>>   return $block['content'];
>> }
>>
>> Then in node/page.tpl.php I do:
>>
>> <?php print phptemplate_get_block(6); ?>
>>
>> Not pretty, and has hard coded block deltas, but it works.
>>
>> The reason is, I don't want the block title to be displayed. I know 
>> that this
>> can be handled with CSS, but prefer not to have it altogether.
>>
>> So on my to do list, there is a task to make it an option to turn off
>> the display
>> of a block's title.
>>
>> Now that block regions can be anywhere, they can be in all sorts of 
>> crazy
>> places.
>>
>> In such situations, the display of the title should be turned off for
>> the region.
>>
>
> I forgot to say that this goes well with the regions and the theme.
>
> In template.php there would be:
>
> function mytheme_regions() {
>  return array(
>      'ad_top'    => t('ad top'),
>      'ad_links'  => t('ad links'),
>      'ad_bottom' => t('ad bottom'),
>      'right'     => t('right sidebar'),
>      'left'      => t('left sidebar'),
>      'content'   => t('content'),
>      'header'    => t('header'),
>      'footer'    => t('footer')
>  );
> }
>
> And then in node/page.tpl.php there would only be:
>
> <?php print $ad_top ?>
>
> And the placement would be via the admin/block interface.
>
> Nice and simple ...
The one downside to this is that, at the moment, a block can only live 
in one region per theme unless I add the blocks to a particular region 
myself.


More information about the development mailing list