-1

I have the Fivestar module installed and have made one of my node field as a Fivestar field. Now I am rendering this field in a template file.

  $settings = array(
              'content_type' => 'node',
              'content_id' => $variables['nid'],
              'entity' => $variables['elements']['#node'],
              'stars' => 5,
              'field_name' => 'field_rating',
              'autosubmit' => TRUE,
              'allow_clear' => FALSE,
              'langcode' => $node_language,
              'text' => 'none',
              'tag' => 'vote',
              'style' => 'average',
              'widget' => array( 'name' => 'oxygen', 'css' => drupal_get_path('module', 'fivestar') . '/widgets/oxygen/oxygen.css' )
              );
  global $user;
  $fivestar_values = fivestar_get_votes('node', $variables['nid'], 'vote', $user->uid);
  $render_form = drupal_get_form('fivestar_custom_widget', $fivestar_values, $settings);
  print render($render_form);
?>

The fivestar field works fine with the only exception that when there are no votes, it shows 4 stars out of five as pre-selected. But once I cast one vote it behaves properly for all users.

How to fix this?

  • You say you are doing this in a tpl, but what tpl? Where are you trying to print the fivestar widget? – rooby Feb 20 '14 at 13:05
  • I am printing this in various template files like this node's tpl, a views style output tpl etc. Does this help? – Pratip Ghosh Feb 20 '14 at 13:40
  • Well if it is a field on the content type and you are in a node tpl why not just print the field as usual instead of all the custom stuff? – rooby Feb 21 '14 at 1:54
  • Rendering the field in a normal way like print render($content['field_vote']); renders the stars but users are not able to cast votes. Apparently it comes in a disabled state. But when I render them like the way I have shown in my question it works fine in regards to the vote casting. – Pratip Ghosh Feb 21 '14 at 11:16
0

Finally after some headbanging I found that it was occurring due to the "tag" attribute. Generally for each node type, its better to create its own tag, and that would fetch you the correct result. I was using the 'vote' tag of another content type. Hence the problem.

Hope this helps someone...

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.