Hello,

I would like to add a region that should appear under node content and before comments.

I tried editing page.tpl.php in order to create a region on the desired position but I realized there's only one "content" variable which also includes both content and comments. I tried to add the region in comments.tpl but it didn't work and I asked myselft whether it's a good practise or not, since I have read that regions should be added into page.tpl.php file only (otherwise that region shouldn't be displayed on pages or views which don't have comments), so I reverted changes.

Can anyone help me, please?

Thank you

Comments

johnalbin’s picture

I have read that regions should be added into page.tpl.php file only

Actually, regions can only be added to page.tpl, because Drupal renders regions and only puts those variables into the page.tpl.

If you really need a region between the node and comments and not some other variable, you could re-use some of the code in theme_blocks() from inside YOURTHEME_preprocess_node().

Something like: if ($list = block_list('my_node_tpl_region')) {, etc., etc. And then saving the the results of the rendered region in a $vars['my_node_tpl_region'] var.

c-c-m’s picture

Thank you very much for your information. Unfortunately I couldn't understand much about it. Can you please explain it a little bit for dummies?

thanks again.

Patrick Mowrer’s picture

I was just wondering the same exact thing and happened to stumble on the commentblock module. It extracts the comments from $content and lets you position it in any region as a block. Hope that helps.

Patrick Mowrer’s picture

Though the comment block module is pretty cool, it caused some unwanted side-effects, like removing "Add new comment" from node's $links. Perhaps there's a proper way to deal with that, but I couldn't figure it out. I disabled comment block, but to my surprise the content I had added between the node's content and it's comments was still showing up in the right place. I had assumed that node.tpl's $content variable included comments, but that wasn't the case.

Adding the region is then pretty simple:

1. Define it in mytemplate.info.

2. Add it to mytheme's template.php:

function mytheme_preprocess_node(&$vars) 
{
   $vars['content_bottom'] = theme('blocks', 'content_bottom');
}

3. Print the region below $content in node.tpl.php:

<div class="content">
   <?php print $content; ?>
</div>       
        
<?php if ($content_bottom): ?>
   <div class="content-bottom">
      <?php print $content_bottom; ?>
   </div>
 <?php endif; ?>
nevets’s picture

Depending on what you want in the region you might find the block reference and/or display suite modules useful.

akalata’s picture

Another way I've accomplished this is using the comment_display module - http://drupal.org/project/comment_display, which gives you a $comments variable that you can play with as if it were a region.

manuel garcia’s picture

Status: Active » Fixed

#4 got it right.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.