Can we change theme() so that an identifier token can be passed to the theme template/function?

I frequently have the problem where I want to target a particular instance of a box/comment/links etc with a slightly different themed output, but can't identify the instance, it's too generic at the tpl.php.. if I make a change for one "links" it changes all.. I often only want to make a change for one

For example, I put a link to #comment-form at the top of the node so the user can jump to the comment form. When you select this link the browser scrolls down to the comment form, but this means the header "Leave a comment" isn't displayed because it is before the comment form. So I want to edit box.tpl.php just for the comment form and put an id on the header there so I can #reference it in the link - I would change the "Jump to comments form" link to link to the header now it has an id, and jumping to the comment form would also display the header

But I can't target a specific instance of box!

So in this example with box.tpl.php the core function comment_form_box() would look like this :

function comment_form_box($edit, $title = NULL) {
  return theme('box'=>'comment-form', $title, drupal_get_form('comment_form', $edit, $title));
}

theme() would still be backwardly compatible with the current method eg; theme('box'...), as the change would just check is_array() on the $hook parameter. In the above eample the string 'comment-form' would be passed along to the theme template/function where I would have a bit of code that says :

<h3 class="title"<?php if($origin == 'comment-form') {?> id="comment-form-header" <?php } ?>>
  <?php print $title; ?>
</h3>

Now the h3 in box.tpl.php has an id just for the comment form and I can have a #fragment link to it

Also the identifier could be used in the template/function finding code so I could have a box-comment-form.tpl.php rather than the code above

There are occasions where it is possible to work around this limitation by overriding a preprocess function, such as preprocess_node() if I want to change how the node['terms'] is themed, for example if I want have a separator between each of the node terms :

$variables['terms'] = theme('links_with_separator', $variables['taxonomy'], array('class' => 'links inline', 'separator' => ', '));

And then create theme_links_with_separator() to include the separator, but it would just be so much easier and more complete if template_preprocess_node() in theme.inc did something lik this :

$variables['terms'] = theme('links'=>node-terms, $variables['taxonomy'], array('class' => 'links inline'));

Then all I would need to do is create a links-node-terms.tpl.php to target the node terms links

And there are other occasions where changes can be made via css but that's different, I'm talking about changing the html output of a theme hook such as the examples above

Please, this change would make me happy what do you think?

See more background at : http://drupal.org/node/313468

Comments

barful’s picture

Noone's interested so sod it, for this and other reasons I've ditched drupal

johnalbin’s picture

Version: 6.4 » 7.x-dev
Status: Active » Closed (duplicate)

Noone's interested so sod it, for this and other reasons I've ditched drupal

That’s too bad because the idea is quite good. :-) Its just the proposed implementation that’s a little off.

See #588148: theme_links() is not really themeable