Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The comment_wrapper.tpl.php file does not provide logic to prevent outputting an empty wrapping div when no comments actually exist:
<div id="comments">
<?php print $content; ?>
</div>
I am filing this as a support request because there may be a valid use-case that needs to be documented. If there is a good reason to output an empty div, please change this issue to the documentation category so we can find a place to explain this behavior.
This template's 5.x predecessor, theme_comment_wrapper(), also lacked logic. Here's an issue from the 4.7.x days that appears similar: [60589].
Comment | File | Size | Author |
---|---|---|---|
#26 | comment.patch | 354 bytes | jmaties |
#21 | comment-wrapper-is-empty-372414-21.patch | 865 bytes | netsensei |
#21 | Picture 3.png | 23.04 KB | netsensei |
#18 | comment-wrapper-is-empty-372414-18-d6.patch | 691 bytes | JohnAlbin |
#16 | comment-wrapper-is-empty-372414-16.patch | 876 bytes | JohnAlbin |
Comments
Comment #1
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedPatch attached.
Comment #2
ainigma32 CreditAttribution: ainigma32 commentedMakes sense to me. Will try applying the patch when I get home.
- Arie
Comment #3
ainigma32 CreditAttribution: ainigma32 commentedPatch doesn't apply. You need to create the patch from the root of Drupal.
- Arie
Comment #4
JohnAlbinsubscribe.
Comment #5
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedRerolled patch to apply to root.
Comment #6
ainigma32 CreditAttribution: ainigma32 commentedWell after this issue you're going to be start patch-maker :-)
Still does not apply. Why is there a mention of modules/comment/comment-wrapper.tpl.php.orig.php ?
Could you try one more time?
- Arie
Comment #7
Todd Nienkerk CreditAttribution: Todd Nienkerk commentedainigma: Thanks for bearing with me here. I've been writing patches for modules for months, but I've rarely done anything with core.
The mention of
modules/comment/comment-wrapper.tpl.php.orig.php
is the originalcomment-wrapper.tpl
file. (The extra .php extension is annoying. I'm trying to do this while attending Drupalcon sessions, so I just ignored it.)I used
diff -up original.php new.php > patch.patch
to create the patch. Should I be doing something differently, likecvs diff
from a checkout? I don't normally mind CVS, but I'd rather avoid it if possible because I've never checked out core.Again, sorry for the elementary how-to stuff. I thought I was far beyond this.
Comment #8
ainigma32 CreditAttribution: ainigma32 commentedNo problem.
Personally I use Eclipse to create patches. I checkout Drupal using CVS and just create a patch using the UI.
So basically I'm just a mouse monkey clicking away :-D
What is important is that you use the Unified format (command line -u I think) and that you choose the drupal root as the root of the patch root. Of course using the UI I can easily select which changes I want to add to the patch and which I want to ignore. I suppose that's a little trickier using the commandline.
Result attached.
- Arie
Hope Murphy's law won't kick in now ;-)
Comment #9
ainigma32 CreditAttribution: ainigma32 commentedHmmm thought I set this...
Comment #10
ainigma32 CreditAttribution: ainigma32 commented@Tod Nienkerk: Since I rolled the last one maybe you can test and review (and set to RTBC if it checks out) ?
- Arie
Comment #11
JohnAlbinIt looks RTBC, but we'll need to apply it to HEAD first. So let's have the testbot have a go at it. Then I'll mark it RTBC. :-)
[edit: Oh! And after that, we can apply it to DRUPAL-6, of course!]
Comment #12
Dries CreditAttribution: Dries commentedI wonder if this is the right approach. Why do we even bother calling the theme system when there is no comment. Sounds like we're checking this at the wrong level. Should this check live somewhere in comment.module?
Comment #13
JohnAlbin@Dries: very. good. point.
Here's a completely untested patch that will only call the theme function if there is content to wrap.
Comment #14
Todd Nienkerk CreditAttribution: Todd Nienkerk commented@JohnAlbin: I'm about to hop on a plane, so I can't brainstorm this at the moment... But can you think of any use cases where you would want to call the wrapper even if there were no comments? I suspect there may be some legitimate reasons.
Comment #16
JohnAlbinHmmm… with this patch applied, I was able to install HEAD and all the comments simple tests past. I have no clue why the patch "failed".
Re-rolled for no good reason.
Comment #17
Dries CreditAttribution: Dries commentedI ran the tests on my machine and everything is fine. Committed to CVS HEAD, and setting the version to Drupal 6.
Comment #18
JohnAlbinOk, I've re-rolled this patch for D6. Its a trivial re-roll, so I'm taking the liberty of leaving this as RTBC. :-D
I did verify the patch works on my D6 test system using Stark (for d6).
Comment #19
Dries CreditAttribution: Dries commentedCommitted to Drupal 6. Thanks! Marking this fix now.
Comment #21
netsensei CreditAttribution: netsensei commentedHm. My site is giving me this when there are no comments (screenshot attached)
'Reacties' is a h4 title inside comment-wrapper.tpl.php in my theme. Comments should be shown below. But there are no comments so it justs shows the h4 and goes on to render the comment form.
$content also contains the comment form box. So it can never really be empty (according to the patch). The code above the patch does that.
Instead of using $content, it would be better to use $num_rows since this variable is set to TRUE/FALSE depending on the presence of comments.
Attached to this comment my patch against HEAD.
Comment #22
JohnAlbin@netsensei
Currently, the comment-wrapper.tpl.php doesn't have a title in it. It just has a single div which wraps the comments and the comment form. As such, the patch that was committed was sufficient to prevent an empty div from appearing on pages.
What you want is slightly different: 1. (possibly) have an H2 title in the comment-wrapper and 2.) not include that h2 title when there are no comments. I think that feature request actually dovetails nicely with this issue #517850: Update and polish default comment-wrapper.tpl.php and associated css, so you should head over there and leave this issue as closed.
Comment #24
dawansv CreditAttribution: dawansv commentedOld story but just want to second Todd Nienkerk (#14) comment... I was actually wondering why comment-wrapper was not running when there is no comment... No I see that's because of this patch. Not a big deal but indeed they are legitimate situations where one might want to run comment-wrapper even if they are no comments...
Comment #26
jmaties CreditAttribution: jmaties commentedHack comment module ;)