-1

D7, bartik. A comment form is created by an .inc file (modulename.page.inc).

This comment form is to comment on existing comments.

To create the comment form, the inc page says:

function _modulename_comment_post_form($form_state, $args, $nid, $uid) {
global $base_url;
// Comment display form.
...
}

Assuming this is the proper way to create the form, how do I select a name for a template file to theme it?

comment.tpl.php and comment-wrapper.tpl.php have no effect on it. Themer devel and theme_debug do not suggest any name for it either.

Thanks. :)

UPDATE:

Here is what I have now in my template.php file:

function stella_theme($existing, $type, $theme, $path) {
$item = array();
// Comment form.
$item['profile_wall_post_comment_form'] = array(
   'arguments' => array('form' => NULL),
   'render element' => 'form',
   'template' => 'templates/profile-wall-post-comment-form',
   'preprocess functions' => array(
      'stella_preprocess_profile_wall_comment_form'
      ),
   );
return $item;
}

Then, I have a profile-wall-post-comment-form.tpl.php file in my templates directory.

Regardless of what I put in the template file, it doesn't show on the comment form. And theme_debug does not pick up the form. All caches have been cleared (more than once.)

A problem with the path? I tried:

'path' => drupal_get_path('theme', 'stella') . '/templates',
'template' => 'profile-wall-post-comment-form',

But to no avail.

What am I doing wrong? Any other idea? Thanks. :)

  • the form itself is normally themed via hook_form_alter() in the theme's template.php and via css... the layout of the comment in general as Niklan describes – Geoff Jul 8 '15 at 0:59
1

You need to understand hook_theme().

function stella_theme($existing, $type, $theme, $path) {
  $theme = array();
// Comment form.
//key comment_form is mean exited function theme
// if key is exited this array will overwrite it.
// You can replace key comment_form with comment_form____node_[CONTENTYPE]
  $theme['comment_form'] = array(
    'arguments' => array('form' => NULL),
    'render element' => 'form',
    'template' => 'templates/profile-wall-post-comment-form',
  );
  return $theme;
}

What Niklan means is that you can replace the template with the name you want, but I think it is better you create a comment-form--node-[content-type].tpl.php file. When you see file you know theme for comment form. And in file tpl use can user this function to show struct your form.

<?php
dpm($form)
?>

after you can print with function drupal_render for element form.

<?php print drupal_render($form['author']['name']); ?>

end file you need print this function

<?php print drupal_render_children($form); ?>
1
  • comment.tpl.php - for comments itself.
  • comment-wrapper.tpl.php - wrapper for comments.

You can also use hook_theme() and define template for comment form. F.e. in template.php

/**
 * Implements hook_theme().
 */
function THEMENAME_theme() {
  $theme = array();
  // Comment form.
  $theme['comment_form'] = array(
    'arguments' => array('form' => NULL),
    'render element' => 'form',
    'template' => 'templates/comment-form',
  );

  return $theme;
}

Then in templates create file comment-form.tpl.php and you'll be able to theme form for comments like you want. P.s. you can name it as you like.

If you done see any effect after create this files, make sure you cleared all caches.

  • Please take a look at the UPDATE above. Thank you. :) – user14666 Jul 8 '15 at 3:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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