provide at the node template as well

der - December 19, 2008 - 16:58
Project:Comment Display
Version:6.x-1.0
Component:Code
Category:feature request
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Provide the $comments variable at the node template level so the comments can be manipulated within the node.tpl.php template.

#1

entrigan - February 23, 2009 - 18:08

I agree whole-heartedly. This is a fantastic module, and making the $comments variable available to all node templates would make it amazing. Also this, or something similar should be part of core.

#2

entrigan - February 23, 2009 - 19:06
Component:Miscellaneous» Code
Status:active» needs review

Ok I opened up the code and it is amazingly simple, so simple in fact, it might better be handled with some functions in your theme's template.php file. Anyway, I basically duplicated the page preprocess function as a new function comment_display_preprocess_node, which then makes the variable available to all node template files.

This is my first patch (simple as it may be) so please let me know if anything is awry.

AttachmentSize
comment_display.patch 917 bytes

#3

sun - February 23, 2009 - 21:21
Status:needs review» needs work

I should probably commit the patch in #326342: Allow to output comments in a block to allow for this feature. Therefore, testing of the other issue would be appreciated.

#4

sn0rcha - July 29, 2009 - 05:22

I can't get that to work in a zen sub theme some reason.

Any ideas?

#5

valderama - August 29, 2009 - 16:14

hi!

did you manage to make it work in a zen-subtheme so far?

greets,
walter

#6

valderama - September 2, 2009 - 06:29

it works for me now... in the end i just put the preprocess function in the template and replaced the "phptemplate" prefix with the name of my theme ("eca"):

function eca_preprocess_node(&$vars) {
$vars['comments'] = '';
if (function_exists('comment_render') && !empty($vars['node']) && $vars['node']->comment) {
$arg2 = arg(2);
$vars['comments'] .= comment_render($vars['node'], ($arg2 && is_numeric($arg2) ? $arg2 : NULL));
}
}

____

in the node template you then have the $comment variable. i also had to print out the $links variable by hand, to get the "login or register to post comments" link, when there is no comment there already:

<?php
         
print $comments;
        
          if(empty(
$comments))
            print
$links;    
?>

hth,
walter

#7

jafar104 - October 28, 2009 - 18:35

Valderama's comments worked like a charm, just changed the theme's name to my theme's name and inserted that into template.php, then added the variable $comments to my node.tpl.php file.

Thanks!

#8

jrao - November 18, 2009 - 11:10

Actually you can just call comment_display_preprocess_page in your template_preprocess_node, instead of copying the code inside that function.

 
 

Drupal is a registered trademark of Dries Buytaert.