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.
By appel on
Hi all,
I was wondering how to customize the content part in page.tpl.php. I wanted to have an additional header '<h3>comments</h3>
above the comment section, but this code print $content;
outputs the entire content and I have no clue how to get to the different sections within the content var (like attachments & comments).
Of course I could use a quick 'n dirty hack for this particular need:
$content = str_replace('<a id="comment"></a>', '<a id="comment"></a><h3>Commentaar</h3>', $content);
print $content;
but surely there must be some better way to accomplish this.
Thanks!
Comments
Maybe you can ge the desired
Maybe you can ge the desired effect by overriding theme_comment_view in your theme?
---
Work: BioRAFT
Thanks
Thank you for your response. Can you give me a code example? I have no idea what to pass as arguments for example. And I would need to substitute $content for something else, right?
Thanks again!
Take a look
Take a look at:
http://api.drupal.org/api/4.7/function/comment_render
in particular:
So, depending on your comment settings you need to override one or all of these 4 theme function.
For example:
http://api.drupal.org/api/4.7/function/theme_comment_flat_expanded
You could probably achieve want you want (note- I have NOT tested this) by putting in template.php for your theme something like:
---
Work: BioRAFT
Gettin' closer...
Thank you for taking the time to help me out, really appreciate the detailed answer. Not there yet, but close. Your function phptemplate_comment_flat_expanded($comment) works to some extend, but it outputs 'Comments on this post:' before each individual comment block, while I (obviously) want the header to appear just once at the top of comments - if any.
I'm using 'comment_thread_expanded' mode and found the appropriate function over here: http://api.drupal.org/api/4.7/function/theme_comment_thread_expanded
Same problem with repeating header though. I figure I need to theme the parent to this function. Am I right?
Thanks again,
ap
Ok, maybe it can be easier
Ok, maybe it can be easier than what I was suggesting.
Look at http://api.drupal.org/api/4.7/function/node_show
The comments are rendered after the entire node body is emitted. Thus, you could make your node.tpl.php look something like (adpating from bluemarine):
I just tried this with my node-forum.tpl.php on a test site, and it seems to work!
---
Work: BioRAFT
That did the trick!
Thanks a bunch pwolanin, it works!
not quite
It seems $node->comment always has content. Still trying to figure that out.
---
Work: BioRAFT
try changing to
prevents the header from showing if there are zero comments
OR:
seems $node->comment determines whether comments can be read/written for that node. So, without the check in the second set of code, the header will still show if comments were made but then comments for that node were disabled.
---
Work: BioRAFT
thnx
Ok, so now it works :) Thanks a lot!
ok, added to the handbook as
ok, added to the handbook as a theme snippet: http://drupal.org/node/76716
---
Work: BioRAFT
Speaking of which, how does
Speaking of which, how does one add a snippet to the handbook?
Perhaps the answer to that could also be added to the handbook :)