Community & Support

Is it possible to get the number of blocks that displayed on a page?

I am using drupal6.15 i would like to know whether it is possible to get the number of blocks that are displayed on a page?
I tried researching a lot but nothing could help me.
My idea is to show block on the leftsidebar when there is no active blocks.
is it possible programatically?

Comments

block count per page

This is actually an interesting question.

Off the top of my head you'd need devise a way to count the number of blocks being displayed per region. This type of count would only be available just prior to outputting. By then it's probably too late to insert another block on the server side so it'd have to be done on the client side (via JavaScript).

You really need something like a hook_blockapi, where you could act on the 'view' operator (i.e. incrementing a global block counter). Your custom module would have to be weighted to execute after all other modules. Note: This *might* be possible w/ Drupal 7, which has a several new block hooks.

That said, this sounds like it's way more trouble than it's worth so you're probably be better off writing a custom snippet to display the block using some other criteria.