How would I change the url of the 'Add new comment' or 'Reply' to pick up a custom page template I created?

e.g.
http://www.example.com/comment/reply/1301#comment-form

change to:
http://www.example.com/custompagetemplate/comment/reply/1301#comment-form

what is happening at the moment is the add/reply to a comment page is defaulting to the normal page template and not my custom template...

maybe there's a better way of picking up a custom template for comments then mucking about with urls?

thanks

Comments

vm’s picture

bib_boy’s picture

thanks Vm, but is that not just for styling the comment bit itself. I want it to take on the page template based on a url (as it has differing header, sidebars etc)...?

i tried the hook_link_alter function in my template.php but no luck...?

function  hook_link_alter(&$links, $node) {
  if($node->type == "news") {

	  $links['comment_reply'] = array(
       'href' => "news/comment/reply/$comment->nid/$comment->cid"
      );

    $links['comment_add'] = array(
               'href' => "news/comment/reply/$node->nid"
              );
  }
  return $links;
}

the news/... url invokes my custom template for news node types.

and ideas?

vm’s picture

hooks go into custom modules not in to template.php

template.php is for preprocess functions and theme overrides.

The issue at hand though is locating the reason why the theme isn't using teh correct tpl.php file for your comments. It should be using the active theme's comment.tpl.php file

bib_boy’s picture

I am not sure what you mean "It should be using the active theme's comment.tpl.php file"

so for example when I am in news/node/161 and I click 'Add new comment' the theme i have for page-news.tpl.php should be used for this comment page? Instead it defaults to the page.tpl.php...I would have thought this would happen but you suggest otherwise? I am lost....

BUT....

comment_link_alter works with template.php (instead of hook_link_alter)

but I have another issue in that I need the url with '#comment-form'...but this comes out in the url as '%23comment-form'

i.e.:

 $links['comment_add'] = array(
               'href' => "news/comment/reply/$node->nid#comment-form"
              );

is news/comment/reply/161%23comment-form in the url...

I am nearly beaten now and users will just have to accept the changing pages templates when they add a comment...very frustrating.

bib_boy’s picture

some way forward...but I obviuosly have missed the point in all this

I used 'fragment'

 $links['comment_add'] = array(
              'title' => t('Post new comment'),
              'href' => "news/comment/reply/$node->nid",
              'fragment' => 'comment-form'
              );

so I can now get www.mysite.com/news/comment/reply/161#comment-form ...thinking it would bring in the page-news.tpl.php...which it did but no comment box...

1 step forward 2 steps back...

robyedlin’s picture

i am also having this issue and haven't been able to find anything about it. mysite.com/comment/reply doesn't really help because I'm using sections, so as of now, all the themes go to one theme for comment/reply/*/*.

anyone have any ideas?

thanks.

claytical’s picture

I'm having the same issue. On the site I'm working on, I have comments on two separate content types. Both of these content types rely heavily on views and have an alias. For example:

http://www.example.com/custom-content-a/node-title
http://www.example.com/custom-content-b/node-title

If the user adds a comment but it doesn't validate, they get redirected to http://www.example.com/comment/reply/nid

I need it to go to a specific path because certain block views show up depending on the path. I've tried redirecting the comment form to go to the path alias with a custom module, but that seems like the wrong thing to change.

darkodev’s picture

I know this is an old thread, but I came upon it and would like to share what worked for us. Our issue was that we were sending users to /user/login, then trying to redirect back to the node comment form. Unfortunately, our fragment 'comment-form' would get stripped, landing the user on the node page, but not on the comment form. Borrowing from comment.module, we rawurlencode the destination, and all works. Perhaps a hint for anyone trying to hack comments.

/**
* Implementation of hook_link_alter().
*/
function agentic_helper_link_alter(&$node, &$links) {
  // if anon users can comment, they should also get option to login to share on facebook via janrain
  if (arg(0) == 'node' && is_numeric(arg(1))) {
    $n = node_load(arg(1));
    global $user;
    if ($user->uid == 0 && user_access('post comments')) {
      $links->links['comment_login'] = array(
        'title' => 'OR login to share comments',
        'href' => 'user/login',
        'attributes' => array('title' => 'Login to share comments on Facebook'),
        'query' => 'destination=' . rawurlencode("comment/reply/$n->nid#comment-form"),
      'fragment' => '',
        );
    }
  }
}