0

I have a problem that I have been working for hours now. Basically, I would like to place a block next to the comments div. So, in the footer of my page, I'd have all the user comments to the left and in the right side, I'd have my block. I know I have to do some realignment in the page.tpl.php, but I just can't get the comments div and the block div to appear side by side. Would appreciate any help on this.

Edit:

I added this in my template.php file:

/**
 * Custom function to render a block to manually position it in the node.tpl.php markup
 */
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;
}

function mytheme_preprocess_node(&$vars) {
    //Add the related_by_term block to the variables array so that we can render it in our node.tpl.php file
    $vars['my_block'] = block_render('views', 'my_block-block_1');
}

And in my node.tpl.php, I added this after the comments section:

<?php print $my_block; ?>

But what I am getting is a memory limit exceeded error. Basically, the block_render function is causing some problem. It's this line that is causing the problem:

_block_render_blocks(array($block));

Any input would be highly appreciated. Spending hours on this issue. Thank you...

  • which theme are you using? or have you created your own custom theme? – Mohammed Shameem Jan 25 '13 at 6:12
  • I have my own custom theme. – SN_26 Jan 25 '13 at 6:33
1

The regions are usually printed in the page.tpl.php

And the comments are printed with in the node.tpl.php

You could follow the below steps to get a region with in node.tpl.php

  1. Add a region in the .info file by adding regions[custom] = Custom
  2. If you already have a preprocess_node in you theme template.php then add the below code or else create a function in the template.php with the name mythemename_preprocess_node(&$variables)

    $variables['custom'] = block_get_blocks_by_region('custom');

This would give you a variable with in the node.tpl.php named custom. This is a renderable array of the blocks with in the region.

Now in your node.tpl.php you would be having something like <?php print render($content['comments']); ?> above or below that you can add

Or you could wrap them in a DIV to suit your requirement.

What ever you add to The region custom would now be displayed near the comments

  • I tried something similar to that. I added a views block and then in my template.php file, added the following code: please check above. – SN_26 Jan 29 '13 at 7:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.