Would appreciate it if someone could let me know how to print a block in node.tpl.php. I basically have a block created through a view and I haven't set a region for that block as I would like to do is display this block in a specific position in all my node pages.
This is what I did in my theme's template file:
function mytheme_preprocess_node(&$vars) {
$vars['my_block'] = mytheme_block_render('views', 'myblock-block_1');
}
function mytheme_block_render($module, $block_id) {
$block = block_load($module, $block_id);
$block_content = _block_render_blocks(array($block));
$build = _block_get_renderable_array($block_content);
$block_rendered = drupal_render($build);
return $block_rendered;
}
And in my node.tpl.php file, I just do:
<?php print $my_block; ?>
However, this is giving me a memory limit exhausted error. I can get it to work perfectly if I render the block in mytheme_preprocess_page function and print it in page.tpl.php, but I need to print this in node.tpl.php. I tried the following as well:
function mytheme_block_render($module, $block_id) {
$block = module_invoke('views', 'block_view', 'myblock-block_1');
return render($block);
}
That is giving me the same memory exhausted error. Is it too later to render a block in the node preprocess function? Why can I render it in the page preprocess function but not in node? Is there some other preprocess function that we can render it in and then have access to it in node.tpl.php?