I try to create a small theme, without using any template files (think about more advanced Stark), just using style file and template.php. I am missing funcionality of theming 'Comments' title and 'Add new comment' title. They are hardcoded in the template file. When I want to add, say, number of comments in the comment wrapper title, I need to override comment.tpl.php. I digged into comment.module and I found, that theming the title is a matter of adding one more variable. Is this possible to extend the template in such way?

The new theme_comment_wrapper would look like this:

function template_preprocess_comment_wrapper(&$variables) {
  // Provide contextual information.
  $variables['node'] = $variables['content']['#node'];
  $variables['display_mode'] = variable_get('comment_default_mode_' . $variables['node']->type, COMMENT_MODE_THREADED);
  $variables['theme_hook_suggestions'][] = 'comment_wrapper__' . $variables['node']->type;
  $variables['title'] = t('Comments');  // Main title
  $variables['add_new_comment'] = t('Add new comment'); // Comment form title
}

And the template file:

<div id="comments" class="<?php print $classes; ?>"<?php print $attributes; ?>> 
  <?php if ($content['comments'] && $node->type != 'forum'): ?>
    <?php print render($title_prefix); ?>
    <h2 class="title"><?php print $title; ?></h2>
    <?php print render($title_suffix); ?>
  <?php endif; ?>

  <?php print render($content['comments']); ?>

  <?php if ($content['comment_form']): ?>
    <h2 class="title comment-form"><?php print $add_new_comment; ?></h2>
    <?php print render($content['comment_form']); ?>
  <?php endif; ?>
</div>

The thing I also miss is a similar functionality for 'Submitted by' message which is also hardcoded, but you can change name and date format in the template.php.

That would be great for theming to have ability to also override these messages in template.php. Then, you just not need to play with tpl files and use in your theme just style.css and template.php.

Any other variable can be overridden in template.php, am I right?

Comments

mariusz.slonina’s picture

Title: Themeable 'Comments' » Themeable 'Comments' and 'Submitted by'
mariusz.slonina’s picture

StatusFileSize
new872 bytes
new472 bytes
new1.08 KB

Proposed patches for comment templates

mariusz.slonina’s picture

StatusFileSize
new432 bytes
new591 bytes

Just the small addition for "Submitted by" in nodes

mariusz.slonina’s picture

Title: Theme API feels to be incomplete » Themeable 'Comments' and 'Submitted by'

With those patches I am able to create a theme without touching default tpl files, just using template.php and very small style.css. It would be great if also "Skip to main content" link could be themeable somehow (maybe just adding classes variable) -- right now, I'm hiding it by duplicating element-invisible class in my style.css.

What I found a little bit confusing is title_attributes in block.tpl. I can add this way css classes, but what about adding a title_classes to block?

Probably it could be also possible to extend theme api to be completely dynamic (think of declaring regions in info file and they are automatically printed, without using page.tpl), probably not before D8.x.

mariusz.slonina’s picture

Title: Themeable 'Comments' and 'Submitted by' » Theme API feels to be incomplete

a, better title

mariusz.slonina’s picture

Title: Themeable 'Comments' and 'Submitted by' » Theme API feels to be incomplete
Version: 7.x-dev » 8.x-dev
Category: support » feature

Since mine is rather edge case, and I didn't have much time to move this issue forward, I'm moving these ideas to 8.x queue

jhedstrom’s picture

Status: Active » Closed (works as designed)

Much has changed since this was last updated. Please re-open if something has been missed.