The comment module allows theming of each comment individually, but there is no way to wrap the entire comment section in its own div... comment_render doesn't allow for that.

Maybe comment_render can be updated to include a call for a themable wrapper around all the comments (default of course would be blank).

Then it will be posssible to address the entire node body and the entire list of comments as separate items on the page without resorting to template markup hackery.

Example of current output:

<div class="node">node body</div>
<div class="comment">comment 1</div>
<div class="comment">comment 2</div>
<div class="comment">comment 3</div>

Requested output:

<div class="node">node body</div>
<div class="comments">
  <div class="comment">comment 1</div>
  <div class="comment">comment 2</div>
  <div class="comment">comment 3</div>
</div>

Since page.tpl.php exposes only $content, it seems most appropriate that this feature should be provided in the comment module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

rkerr’s picture

Status: Active » Needs review
FileSize
1.71 KB

Created a new function theme_comment_wrapper()

This is called after all the comments have been themed, at the end of comment_render() and puts a div with id="comments" as well as the anchor id="comment" around the already-themed comments.

m3avrck’s picture

I agree 100%. I ran into this problem on a previous project, this needs to be fixed.

The approach to this patch looks solid.

Tobias Maier’s picture

+1 for more flexibility and themability

is <a id="comment"></a>
really needed after this patch, because the div works as anchor, too...

in general I'm against introducing new ids in drupal, because we loose flexibility with them
--> maybe someone wants to show two full nodes with a module like dashboard, what he gets is an id conflict...

RobRoy’s picture

FileSize
1.64 KB

We should be able to scrap the anchor as it is a duplicate ID. Here's a revised patch.

rkerr’s picture

I kept the "comment" anchor because it was in the original function. I guess it is used somewhere for linking through to node/xxx#comment. But why it was using id instead of name I'm not sure.

We might need to retain some kind of anchor for jumping directly to comments.

rkerr’s picture

Whether the wrapper around the comments has an id or class, I don't really have a preference either way.

RobRoy’s picture

Using a DIV with ID="comment" allows users to still go to page#comment. IIRC, in HTML 4 any page#whatever will go to any HTML element that has ID="whatever" so this will still serve that purpose and not serve up a duplicate ID.

rkerr’s picture

FileSize
1.64 KB

Yeah you're correct. :) Why hadn't I noticed that before?

OK, so I'd say for minimal disruption to the default core markup, remove the anchor and keep the same id="comment" on the wrapping div.

(attaching updated patch)

RobRoy’s picture

FileSize
1.64 KB

Oops, thought that's what I had done. I updated your patch removing the unneeded backslash.

Looks good to me know and ready for review!

rkerr’s picture

Oops. :) Thanks for updating that!
Let's see if we can get some eyes on this...

m3avrck’s picture

Not to nit-pic, but wouldn't it make more sense for that to be <div id="commentS"> ... make it plural, as there are many times I use class="comment" for individual comments.

Otherwise looks solid, about time that <a> was removed :-)

rkerr’s picture

I think plural does make more sense, but wanted to keep the default id the same so that any other code that tires to link to node/id#comment will still work. (Without going on a find/replace in the rest of the modules).

m3avrck’s picture

Bah! Drupal breaks so much from version to version, a simple "comment" to "comments" should suffice ;-)

I would imagine there is only a handful of links to "comment" in the code, maybe less. I can only think of one instance it exists so yeah.

Otherwise patch is awesome!

rkerr’s picture

Someone with commit access can decide what the final id will be ;) Either way, the themability is the imporant part!

RobRoy’s picture

FileSize
1.64 KB

I agree, we'll brake some stuff, but it makes more sense this way. New patch for HEAD with plural class ID "comments".

m3avrck’s picture

Status: Needs review » Reviewed & tested by the community

Awesome, I think this is ready, here we go!

rkerr’s picture

Bonus: Drupal node urls will be consistent with wordpress urls, using #comments (plural) to jump to the comments on a given post.

drumm’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD.

I changed a couple links to match the change in the url fragment from 'comment' to 'comments'

Anonymous’s picture

Status: Fixed » Closed (fixed)