Hallo,
I need to theme the "my-domain.com/comment/reply/$node->nid" page.

With the devel modul I can see the theme_hook_suggestions:

  • page__comment
  • page__comment__reply
  • page__comment__reply__%
  • page__comment__reply__27

Well here is my problem:
I have a "page--blog.tpl.php" a "page--book.tpl.php" and a "page--forum.tpl.php". All of them have a different theme or rather css layout.
On every page my users can post comments.
If my users preview their comments they always see the "page--comment--reply.tpl.php".

How can I make the comment preview like that:
If a user post a comment to a blog post, the preview page is the "page--comment--reply--blog.tpl.php".
If a user post a comment to a book post, the preview page is the "page--comment--reply--book.tpl.php".
If a user post a comment to a forum post, the preview page is the "page--comment--reply--forum.tpl.php".

You can see my problem in the attachment too.

CommentFileSizeAuthor
forum-theme-.jpg26.73 KBfalloutboy
blog-theme-.jpg24.92 KBfalloutboy
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Konstantin Boyandin’s picture

Definitely, something should be done about comment/reply

Apart from possibility to assign per-node type template for comment/reply, a special type of aliases is suggested to add. So that the actual page address looked like

nodetypename/comment/reply/nid
i.e.
blog/comment/reply/12345

heretic381’s picture

Any news for this issue?

A major fix is needed here, as comment reply page breaks the page per content-type custom templates.

NaheemSays’s picture

You can add further theme suggestions as needed:

https://drupal.org/node/1142800#comment-4433994

heretic381’s picture

Hi,
I don't really see what are trying to point out here.
I know how to make a template per content type and I'm already using them.
The problem is that whatever template we are using, the comment-reply page is not related to it. If someone posts a comment on certain type of node, he's going to click on create new comment, or reply link and the page he's going to be redirected to is using page.tpl.php (or at best page--comment--reply.tpl.php) and that is not always what we want. We need a different template for comment reply page per content type.

Thanks.

NaheemSays’s picture

Something like this in your theme template .php


function MYTHEME_preprocess_page(&$variables) {
    $args = arg();
    
    if ($args[0] == 'comment' & $args[1] == 'reply') {
      $node = //figure out how to load node. comment id is $args[2].
      $variables['theme_hook_suggestions'][] = "comment--reply--$node->type";
    }
}

heretic381’s picture

Thanks for the idea. But, I'm not skilled enough in php and drupal API to figure out how to make this work.

"//figure out how to load node. comment id is $args[2]."

NaheemSays’s picture

oops $args[2] was the nid.

The full function you need is:

function MYTHEME_preprocess_page(&$variables) {
    $args = arg();
   
    if ($args[0] == 'comment' & $args[1] == 'reply') {
      $node = node_load($args[2]);
      $variables['theme_hook_suggestions'][] = "page--comment--reply--$node->type";
    }
}
heretic381’s picture

Category: support » feature
Priority: Normal » Major
Status: Needs work » Active

When changed "page--comment--reply--$node->type" to 'page__comment__reply__'.$node->type'

it worked.

Thanks.

NaheemSays’s picture

Category: feature » support
Priority: Major » Normal
Status: Active » Closed (fixed)
ShaneOnABike’s picture

Status: Closed (fixed) » Needs work

I *hate* to re-open this but actually I realized an issue here with comments.

On a regular page the comments section calls the hook comments_wrapper and also the appropriate template. For some bizarre reason there isn't an equivalent hook nor template file for comments replies :(

Thoughts? I think the title is still fairly relevant actually.

Pasqualle’s picture

Category: feature » support
Priority: Major » Normal

if you want a different comment.tpl.php template per node type
https://api.drupal.org/api/drupal/7/search/preprocess_comment

function MYTHEME_preprocess_comment(&$variables) {
  $variables['theme_hook_suggestions'][] = 'comment__' . $variables['node']->type;
}

If you need something else, please explain your issue a bit more.

bdanin’s picture

Issue summary: View changes
Status: Active » Closed (fixed)

So when you add this to your template.php file:

<?php
function MYTHEME_preprocess_page(&$variables) {
    $args = arg();
   
    if ($args[0] == 'comment' && $args[1] == 'reply') {
      $node = node_load($args[2]);
      $variables['theme_hook_suggestions'][] = "page__comment__reply__$node->type";
    }
}
?>

You can then copy your page.tpl.php into page--comment--reply.tpl.php (don't forget to clear caches!), to theme all comment-reply page templates, or you can also add page--comment--reply--CONTENTTYPE.tpl.php for specific content-type pages.

This seems like it fits well within the standard "Drupal way" of theming for reply-pages.