Hello,

is there an easy way to have content shown between the node and its comments? As the Comment Module doesn't provide a block for the comments, it can't be done by rearranging blocks.

What I tried:
- changing comment.tpl.php
I tried to put the content of the region in front of the comments by adding it in the comment.tpl.php above the comment code, but that didnt produce any output. Seems as the region variables (for example $content_bottom) arent available in this template.

- node.tpl
Unfortunately the whole node content including comments is in $content, so there no way to put something in between.

So, is there a comfortable way to do what I want? An uncomfortable way would be to set the content via hook_nodeapi()....

Best regards
Philipp

Comments

yuriy.babenko’s picture

I think this can be done, but it will be trisky ;).

Give this a shot:

In comment.tpl.php, put everything (including HTML) into a global variable:

global $comments_data;
$comments_data = 'the actual data here';

And, don't print/echo/output anything in this file.

Then just make a new block with the following content (PHP Input enabled):

global $comments_data;
print $comments_data;

And... you can make other blocks that go above this one.

Let us know how it goes.

---
Yuriy Babenko
www.yubastudios.com
My Drupal tutorials: http://yubastudios.com/blog/tag/tutorials

---
Yuriy Babenko | Technical Consultant & Senior Developer
http://yuriybabenko.com

pmg’s picture

Hello Yuriy,

this works, thanks! Unfortunately, it only puts the comments itself in a block, not the comment form. Is there a way to place the comment form in a block, too?

Best regards
Philipp

spiffyd’s picture

What if the comment.tpl.php is complex with php conditions and such?

Can all of this still go in the $comments_data string?

---
Like what you see? Leave a tip!
spiffy[d] | simplicity is bliss

Jeff Burnz’s picture

You can assign a region to node.tpl.php in Drupal 5, which will allow to you print content between the node content and the comments (comment form prints below node content or comments as per normal).

You need a couple of things - a new region & set a variable in phptemplate_variables in template.php and finally print the region in node.tpl.php.

As an exercise I did this for Bluemarine in Drupal 5.

template.php - create a new region and make it available in node.tpl.php

<?php
// regions
function bluemarine_regions() {
  return array(
    'left' => t('left sidebar'),
    'right' => t('right sidebar'),
    'header' => t('header'),
    'footer' => t('footer'),
    'content_bottom' => t('content bottom'),
    'closure_region' => t('closure'),
  );
}
function _phptemplate_variables($hook, $vars = array()) {
  global $user;

  switch ($hook) {
  
    case 'page':
      break;

    case 'node':
      $vars['content_bottom'] = theme('blocks', 'content_bottom');
      break;

    case 'comment':
      break;
  }
  return $vars;
}

node.tpl.php

  <div class="node<?php if ($sticky) { print " sticky"; } ?><?php if (!$status) { print " node-unpublished"; } ?>">
    <?php if ($picture) {
      print $picture;
    }?>
    <?php if ($page == 0) { ?><h2 class="title"><a href="<?php print $node_url?>"><?php print $title?></a></h2><?php }; ?>
    <span class="submitted"><?php print $submitted?></span>
    <span class="taxonomy"><?php print $terms?></span>
    <div class="content"><?php print $content?></div>
    <?php if ($links) { ?><div class="links">&raquo; <?php print $links?></div><?php }; ?>
	
    <!-- the new region in a div -->
    <div class="content_bottom"><?php print $content_bottom; ?></div>
  </div>

Now you can print whatever you want there in block etc etc.

Another way (yes, there is another way!) - if the content you want to print is a View, just print the view directly in the node template, e.g if your view is a block view...

<?php
  $view_name = 'myview'; //name of view
  $view_args = array();
  $view = views_get_view($view_name);
  print views_build_view('block', $view, $view_args, FALSE, $view->nodes_per_block);
?>

Hope that helps some, good luck!

freedomhonal’s picture

Thanks that realy helped!

hedac’s picture

how to do this in drupal 6 ?

spiffyd’s picture

I second this... help for Drupal 6 would be appreciated!

mean0dspt’s picture

spiffyd’s picture

@mean0dspot... that post did not help.

My blocks in the "content" region still display below the "Post New Comments" block even with that snippet of preprocessing code.

mean0dspt’s picture

yes, and they will. what you should do is creating ADDITIONAL region, named in the example "content_bottom" and assign blocks to it, NOT to "content" region
it takes 3 code edits:info file, node.tpl.php file AND preprocessing function

superxain’s picture

New created region has no problem shows above "Post New Comments" string. You just need to add the region code to the right place (right after content section ) of your node.tpl.php file. See result and a step by step on my post :
http://www.o-learn.com/content/drupal-6-how-to-create-a-new-block-region...

dinknaround’s picture

As an FYI...And I too am trying to figure this out, and create a module with my custom functions. So far, just to let you all know, in response to what pmg's said:

- node.tpl

Unfortunately the whole node content including comments is in $content, so there no way to put something in between.

I my hours of digging I found that comments are NOT part of a nodes $content, and it takes a ton of functions to show a single node. Refer to the API node_show. And note that node_show is not the last function before a full node is shown, it is called by another function.

Creating a region is a good idea, or modifying the the node template. If it is at possible through a custom module to have content render between node and comments would be great too, without the user having to modify their node template, but I haven't found the solution to that yet without hacking core. What best to do probably depends on "what" a person is trying acheive.

Jeff Burnz’s picture

rahim_vindhani’s picture

I googled around to search this problem and found below URL
http://www.innovatingtomorrow.net/2007/12/11/how-embed-region-node

But you know what, it missed the last step i.e. print the blocks in node.tpl.php file :)

Thank a lot for complete steps.. You could see it working here Java Examples now.

Regards,
Rahim.

wismbuh’s picture

how about D7?
please explain..