Drupal Block Within a Block
I recently came across an issue where I needed to figure out how to place a block-within-a-block on a Drupal site. The client was using a custom block to pull a random view from the database using a simple PHP script in the block body. The script was a rudimentary if-then statement that generated a random number then pulled a view based on it.
My task was to integrate a block with the pool of possible random views. Turns out it is pretty simple. In the block body (be sure you're using the PHP input format), to grab a view, you use this:
To modify this to pull a block, I used this:
The module_invoke function in this case takes 4 arguments: the module's name that the block belongs to, the strings 'block' and 'view' to indicate what we'd like the function to return, and the block ID - in the example above: 0.
If you want to use a custom block, the 'module_name' is 'block'. Just be careful that you don't try to include a block in itself - sounds like an infinite loop waiting to happen...
Filed under:

Post new comment