Hi everyone!
I think that the documentation actually available isn't enough to make a custom template.
I've copied the rate-widget.tpl.php to rate-widget-NAME.tpl.php (NAME being the machine readeble widget name setted in administration panel - just as is explained in the README) and put an additional html paragraph just to test the template working. But it don't.
What's missing to make it work?

Thanks in advance!!!

CommentFileSizeAuthor
#16 rate-custom_template-1262438-16.patch662 bytesronino

Comments

mauritsl’s picture

Status: Active » Postponed (maintainer needs more info)

The name should be rate-widget--NAME.tpl.php, with 2 dashes. Does that fix your problem?

danilocgsilva’s picture

No, it don't!

danilocgsilva’s picture

Sorry for saying, but it seems that it was never able to make a custom template.

Tested in 6.x-1.2, 6.x-1.1, 6.x-1.0 and 7.x-1.1-beta1. None of them works with the following procedures:

  1. Installing a drupal on apache's home directory
  2. Unpacking the votingapi, rate and devel modules to the /sites/default/modules (devel just to creating dummy content)
  3. Enabling Devel Generate Content and Rate and accept to enable the Voting API module
  4. Generate users and contents with comments
  5. Creating a Custom Widget (I used to put gng both as machine readable name and tag)
  6. Sometimes, I added an additional line in the end of rate-widget.tpl.php containing a html paragraph just to watch de template modification
  7. Finally, copy the rate-widget.tpl.php to rate-widget--gng.tpl.php (in the same location) and modify (or create, if it was not done before) the content of paragraph to watch the result in the site.

Doesn't worked.

Someone can assure that the module actually does let themers creates yours own custom widget templates or there are a real bug on the module?

Thanks in advance!

pierrecw’s picture

Hello,
I've the same problem !! But in the 7.x-1.2 version.

I've a rate widget "custom" call All rate (machine name = all_rate). When i create rate-widget--all-rate.tpl.php the template don't work !

@danilocgsilva do you find a solution ?

danilocgsilva’s picture

Not as I would like.

My "solution" was to modify the css and tpl.php of one of the default templates, so I make the look I want. So, standardized modifications have to be maden everytime the module is changed (I wish that the next code administrator pay attention on the outsider files inside module that teaches what modifications have to be maden to preserve the widget look...)

Custom template continues useless...

yang_yi_cn’s picture

Status: Postponed (maintainer needs more info) » Fixed

ok, I finally got it working.

The point is, you need to have 2 template files in your theme:

rate-widget.tpl.php

AND

rate-widget--your-widget-name.tpl.php.

Without the first one (original template file), the Drupal theme system will not recognize the second one. I tested that on the 7.x release but should be the same for 6.x.

jim005’s picture

Version: 6.x-1.2 » 7.x-1.3
Status: Fixed » Needs work

Your solution isn't working for me. So I copy the module Rate into /example.com/modules/ then edit the original tpl : thumbs-up-down.tpl.php

Thanks to fix this issue :-)

mototribe’s picture

it doesn't work for me either.

My rating widget is called rate_updown and I have the rate-widget.tpl.php and rate-widget--rate-updown.tpl.php in my templates directory. But they don't override the module template.

vlad.dancer’s picture

Here how I implemented it. For me it's needed that rate template will be in my module and widget type was "+1".

Solution for theme:

  1. Implement in your theme THEME-NAME_preprocess_RATING_THEME (for example: mytheme_preprocess_rate_template_number_up_down) and define theme_hook_suggestions (ex:
    $vars['theme_hook_suggestions'][] =  'rate_template_number_up_down__mytheme';
    

    ).

  2. Add to theme template folder template file (ex: rate-template-number-up-down--mytheme.tpl.php).
  3. Clear cache

Solution for module:
Just as I said about, but we need to say theme that our module has some templates for it too). In mymodule_theme() add this line:

$items += drupal_find_theme_templates($existing, 'tpl.php', drupal_get_path('module', 'mymodule') . '/templates/theme');

I hope that this will help someone!

sepehr.sadatifar’s picture

my custom template works without the base template (rate-widget.tpl.php) but the problem is that it doesn't recognize `$up_bottom` and `$down_button` so there is no `a` tag and in result functionallity is broken.
[edit]: sry `$up_bottom` and `$down_button` is only for `number-up-down` widget type , for custom widget type you can use variables defined in base template file (`rate-widget.tpl.php`).

vlad.dancer’s picture

Use hook_rate_templates to define own template and widget and after that add preprocess theme func add define your buttons

function ownmodule_rate_templates() {
  $templates = array();
  $templates['own_rate_widget']->theme = 'own_rate_widget';
  return $templates;

function ownmodule_theme() {
  $theme['own_rate_widget'] => array(
      'variables' => array('links' => NULL, 'results' => NULL, 'mode' => NULL, 'just_voted' => FALSE, 'content_type' => NULL, 'content_id' => NULL, 'display_options' => NULL),
      'template' => 'own-rate-widget',
      'path' => drupal_get_path('module', 'ownmodule') . '/templates/own-rate-widget',
  );
  return $theme;
}

function ownmodule_preprocess_own_rate_widget(&$vars) {
  extract($vars);
  $vars['up_button'] = theme('rate_button', array('text' => $links[0]['text'], 'href' => $links[0]['href'], 'class' => $up_classes));
  $vars['down_button'] = theme('rate_button', array('text' => $links[1]['text'], 'href' => $links[1]['href'], 'class' => $down_classes));
}
MD3’s picture

@vlad.dancer thanks so much! You're a genius!

Just to clarify the instructions: you need to create your own custom module for this work. So:

  1. Make a folder in sites/all/modules called ownmodule (side note, I personally have a folder called custom that I keep all of my custom modules in).
  2. Create a ownmodule.info and ownmodule.module file in the folder
  3. You can copy / paste the rate.info file from sites/all/modules/rate into ownmodule.info and change the name rate to ownmodule
  4. Then copy / paste vlad.dancer's instructions into the ownmodule.module file
  5. Create a directory called templates
  6. Copy a template folder from sites/all/modules/rate/templates that you want to start from into sites/all/modules/ownmodule/templates
  7. Change the name so that it's sites/all/modules/ownmodule/template/own-rate-widget
  8. Make sure the .tpl.php and .css file match the folder name (own-rate-widget)
  9. Make your custom modifications to own-rate-widget.tpl.php and own-rate-widget.css
  10. Enable your module (drush en ownmodule or via modules page).
  11. Use your custom widget!

You should have the following files / folders in: sites/all/modules/ownmodule:

  • ownmodule.info
  • ownmodule.module
  • templates
  • templates/own-rate-widget
  • templates/own-rate-widget/own-rate-widget.css
  • templates/own-rate-widget/own-rate-widget.tpl.php
  • templates/own-rate-widget/{any image files you need such as thumbs.jpg}

Good luck!

vlad.dancer’s picture

@MD3
Thx a lot for summarizing.

webdrips’s picture

Here's my fivestar theme-only approach thanks to @vlad.dancer (#9)

  1. In template.php add function MYTHEME_preprocess_rate_template_fivestar(&$variables)
  2. In this function copy the code from the rate.module function rate_preprocess_rate_template_fivestar
  3. Copy rate/templates/fivestar/fivestar.tpl.php to MYTHEME/templates and rename it rate-template-fivestar--MYTHEME.tpl.php
  4. Clear theme registry

This gives you two places to override the output, so you should be able to achieve the desired output.

ronino’s picture

Well, I can confirm that it doesn't work as described in the README.txt:

Default templates for theming are:

* rate-widget.tpl.php
This is the default template for all custom widgets.
* rate-widget--NAME.tpl.php
This is a widget specific template. Use the machine name for NAME. Replace
underscores by dashes in this name. This template is only available for custom
widgets.

So shouldn't this be considered a bug report?

Did it ever work? Otherwise it wouldn't be in the documentation, I guess. Those hooks and theme functions described above shouldn't be necessary, should they? For example, using THEME_preprocess_rate_template_yesno() to define a custom template only works for ALL yes/no widgets, not a specific one as it is expected with rate-widget--NAME.tpl.php.

ronino’s picture

Version: 7.x-1.3 » 7.x-1.4
Category: support » bug
Status: Needs work » Needs review
StatusFileSize
new662 bytes

The attached patch fixes the issue and makes custom widget templates be recognized and used as described in README.txt. The problem were lines 238 to 243 in rate.module:

$theme_name = str_replace('-', '_', $widget->name);
$theme = array('rate_widget__' . $theme_name, 'rate_widget');
if (isset($widget->theme)) {
  // This overrules the default theming pattern. Used for templates.
  $theme = $widget->theme;
}

The first two lines correctly set e.g. "rate_widget__my_widget" and "rate_widget" as template suggestions. But the 3rd line always overwrites those and sets e.g. "rate_template_yesno" as the one and only.

The patch now makes templates be used in the following order (if existent):

  1. rate-widget--my-widget.tpl.php
  2. rate-template-yesno.tpl.php
  3. rate-widget.tpl.php
mauritsl’s picture

Status: Needs review » Fixed

Committed to GIT. Thanks!

Lythimus’s picture

rate-template-yesno.tpl.php worked fine for me.

ronino’s picture

Lythimus wrote:

rate-template-yesno.tpl.php worked fine for me.

It should work with and without the patch. Didn't it for you? Where did you put the template?

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

ivnish’s picture

Assigned: danilocgsilva » Unassigned
Issue summary: View changes