Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 370 Vote(s) - 3.56 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to insert a block into a node or template in Drupal 7?

#11
Improving wrburgess' answer, you can do it in one line...

<?php print drupal_render(_block_get_renderable_array(_block_render_blocks(array(block_load('module_name', 'block_delta'))))); ?>

So for example, I use block number 6...

<?php print drupal_render(_block_get_renderable_array(_block_render_blocks(array(block_load('block', '6'))))); ?>
Reply

#12
There's module called [**insert_block**][1] for those which want to insert block "Drupal way" (not to program anything, just enable the module). [**Here**][2]'s how to set it up.

**NOTE:** I know this question is about "programmatically inserting a block into a template or node" but Google sends people here even their are looking for non-programmer solution like me.


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#13
Recently I faced the same issue and I came across a nice solution which describes the solution in drupal as drupal's way.

You can print regions inside any template, but they aren't available out of the box in the node.tpl.php template. To make them available, you'll create a new variable for use in your node.tpl.php template that'll contain all the region content.

Creating new template variables is done by using a preprocess function. In your theme's template.php file, create a function that looks like this:

function mytheme_preprocess_node(&$variables) {
// Get a list of all the regions for this theme
foreach (system_region_list($GLOBALS['theme']) as $region_key => $region_name) {

// Get the content for each region and add it to the $region variable
if ($blocks = block_get_blocks_by_region($region_key)) {
$variables['region'][$region_key] = $blocks;
}
else {
$variables['region'][$region_key] = array();
}
}
}

Then, in your theme's node.tpl.php template, you can render any region by doing the following:

<?php print render($region['sidebar_first']); ?>

Where sidebar_first is the name of the region you want to render.

Read the complete article here:

[To see links please register here]

Reply

#14
For some reason `render()` doesn't work for me, but this does:

<?php
$block = module_invoke('block', 'block_view', '1');
echo $block['content'];
?>
Reply

#15
**module_invoke** Working fine for render block in the template file, but it's not working multilingual sites.
Reply

#16
This worked for my Drupal 7 ,
URL: admin/structure/block/manage/**addthis**/**addthis_block**/configure
NOTE:delta and module name present in the url itself

`$addblock = module_invoke('addthis','block_view','addthis_block');`
`print render($addblock['content']);`

More information can be found on

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through