I was wondering if there is any way to decide to show a block from code, but inside a module code.
I've seen that there's an option (from admin pages) to add code to decide if a block must be shown, but I need to decide this from my module because the decision is a bit complex and I need to check it inside some hooks...

Any help would be appreciated.

Comments

ludo1960’s picture

<?php
$block = module_invoke('theblockyouwanttouse', 'block', 'view', '0');
print $block['content']
?>
savioret’s picture

Thanks ludo,

But what I dont understand, is that if I make a print I'll show the block content inside the page content...
How do I show it in its right place?

ludo1960’s picture

..is the right place?

savioret’s picture

The place where the block has been setup for. For example in my case I setup the block to be shown in the left side, in the upper position.
Where should I use the print to show the block exactly in the region where it was configured to be ?

I think another solution could be setting a block to be *always* shown, and return nothing in hook_block when I don't want it to be shown. But this always generates a hook call for every page load.

ludo1960’s picture

Why not place the code in the page.tpl, you can use a php if() clause to test for your condition?

savioret’s picture

Hmmm... that's the same situation as setting the code from the admin pages. The problem is that I need to show the block when certain hook is invoked, and using global variables would be quite dirty...