In drupal 7, I want to render block into another block, for example block-1 into block-2. I guess I should put some PHP code into block-2, but I don't know what the code could be?
Based on Ashlars's comment.
A minipanel, provided by Panels, is for anyone not used to Panels, essentially a block, that supports internal layouts. You can use a mini-panel to wrap several different blocks (and many other things, views, nodes, etc) into a single "block".
Unfortunately, I must admit that documentation is scarce on this topic. I will refer you to this other question: looking for a good mini panels tutorial.
Completely agree with Letharion's comment but if there is absolute need for such, this code snippet can help:
<?php //D7 $block = module_invoke('module_name', 'block_view', 'block_delta'); print render($block['content']); ?>
If you are unsure what are exact parameters for 'module_name' and 'block_delta' I'd recommend searching the database table block and locating your specific
- module_name under column module
- block_delta under column delta
second parameter block_view remains exactly like that.
Late answer for anyone who comes across this.
I am not sure if this covers the specific requirement of the original question: The original question wants to insert block-1 into block-2. What I am proposing here allows to create a new block which combines two existing blocks.
Follow the instructions on the module page:
- Install cfrblock, renderkit, cfrpreset. This involves some composer packages, you will find instructions on renderkit module page.
- Go to admin/structure/cfrpreset, add a preset for "BlockInterface".
- Configure the block as you like.
- Go to admin/structure/block. The presets you just created will appear there as blocks.
Possibilities when configuring the block:
- Sequence of elements (blocks or other things). This is, I think, what you want here.
- Views display.
- Views exposed form.
- Existing block.
- Element wrapped into a special container.
- Combination of the above, with endless nesting.
If you are crafty and creative, you can create your own elements and then recombine them into a block.
I am using this on a website where I have more custom plugins than you currently find in renderkit. I should add some of those to the contrib module..
NOTE: This is essentially the same answer I gave here, https://drupal.stackexchange.com/a/288747/2974. It applies in both cases.