3

When CCK was not in core, as in Drupal 6, and you selected a node type for comments on other node types, the comment form would say the name of the content type instead of comment. In this case, I want the comment form to say 'Add New Review' instead of 'Add New Comment'. Does anyone know how to do this through a module or configuration?

2
  • 1
  • In addition to these examples, if you are using Panelizer to Panelize your node pages to layout your content note that tpl template files are available for panels, if you use the Devel_Themer module (with Devel), turn it on and hover over your panel it will suggest the file you need to create (and also the file whose contents you would need to base it off). I've had success with this. Feb 12, 2014 at 18:23

5 Answers 5

8

Create a seperate .tpl file for comment-wrapper named comment-wrapper.tpl.php.

To create a seperate template file for node specific comment wrapper you can create using comment-wrapper-contenttype.tpl.php copy the code from core comment-wrapper.tpl.php and change the title in the code given below.

While copying from core comment-wrapper.tpl.php don't forget to remove the validation which is meant for forum node types only.

<h2 class="title comment-form"><?php print t('Add new comment'); ?></h2>
2
  • +1 definitely the best answer as the default base theme file comment-wrapper.tpl.php contains the very string that is output as @mohit_rocks says: Add new comment. This replace per content type is a nice approach, particular if your want to use comments differently for a certain content type, e.g. [drupal.org/project/question_answer](question_answer) module which uses comments as answers. Sep 4, 2013 at 11:05
  • 1
    Minor correction to @mohit_rocks' great answer on the name of the file you'd use for your content type - it would be comment-wrapper--node-[type].tpl.php where [type] is the name of your content type. Examples: if your content type is called question, then the file would be comment-wrapper--node-question.tpl.php. If your content type is called Resource Article (note the space!) then the file would be: comment-wrapper--node-resource_article.tpl.php - note the space is replaced with an underscore _ Works for me, based on official documentation here: drupal.org/node/1089656 Sep 4, 2013 at 11:09
8

You can do it by implementing hook_node_view_alter(), in your module or theme(template.php).

function myThemeOrModule_node_view_alter(&$build) {
  if ($build['#node']->type == 'page') {  //extra check for content type (optional)
    $build['links']['comment']['#links']['comment-add']['title'] = t('Add new review');
  }
}
5
  • above code is not working properly. It will stop ajax working in your site as well as other error also. Oct 22, 2012 at 12:36
  • @mohit_rocks could you please throw some light on it? any specific reason?
    – AjitS
    Oct 22, 2012 at 14:46
  • 1
    At very first moment i tried your solution, as it seems better than my solution as shown below, then i tried both the way from module and theme. When i tried in module file it is showing error. Recoverable Fatal Error Argument passed to l() must be an array string given called: in theme.inc on line 1712 and defined in l() line 2345 of commons.inc Oct 22, 2012 at 15:56
  • @mohit_rocks nice catch, thanks! see the edit for the working(tested) solution :)
    – AjitS
    Oct 23, 2012 at 7:11
  • 1
    Cool..Now your solution is better than mine.. Oct 23, 2012 at 7:15
3

You can use the "strings override" module to change the text.

1
  • 1
    String override work everywhere and is not specific to one content type
    – the1brit
    Oct 22, 2012 at 1:06
2

Open your settings.php file and under 'To override specific strings on your site ...' add the following:

$conf['locale_custom_strings_en'][''] = array(
  'Comments'      => 'Reviews',
  'Add new comment' => 'Add new review',
);

Make sure you have permission to edit settings.php.

-3

You could do it from the comments-wrapper.tpl.php (or check comments.tpl.php too) file in the comments module (/modules/comments)

1
  • 7
    It is not recommended to change any thing in Drupal core modules, as all changes might get lost when you update drupal version. Oct 22, 2012 at 6:38

Not the answer you're looking for? Browse other questions tagged or ask your own question.