How do I use the user rating widget in a custom profile or custom node template?

Comments

Richard Blackborder’s picture

I'm no expert at the theme system. I can tell you that the Fivestar Extra widget is added to the $account object as $account->content['fivestarextra']['widget']. I don't know if that helps.

TechnoBuddhist’s picture

I've just tried to print the contents of the account object on a node page and there was no reference to fivestarextra at all.

I copied profile-block.tpl.php to my theme and added the following code;

print '

'. print_r($account, TRUE) .'

';

It showed a lot of things, but it didn't show fivestarextra.

This block shows all the profile fields and the picture of the user and I want to show the fivestarextra user rating at least. If I could get the voting part as well without going to the user page then brilliant, but it won't even show the current rating.

Am I doing something wrong?

Richard Blackborder’s picture

Try $profile instead. I output $profile in user-profile.tpl.php and got an element 'fivestarextra' containing a bunch of HTML.

Richard Blackborder’s picture

Status: Active » Fixed
Nigeria’s picture

Could someone please show me a code example for

a) a page or node
b) a block

Thanks in advance

Richard Blackborder’s picture

Nigeria I don't know enough about theming to give you the best answers on how to do this. With what knowledge I have, I'll try to point you in the right direction:

What you are looking for is either a way to get a $profile object or a $user object. If you get the $profile object, the widget is in $profile['fivestarextra'].

Pages, nodes and blocks don't come with these objects included (at least from what I can see), so you would need to know which user you wanted the widget for and then go fetch the $user object for that user.

For that kind of info and understanding, you need to go learn a bit more about theming. A Fivestarextra issue is not the best place to do that because you're not asking experts here. Go read Drupal theme stuff.

Status: Fixed » Closed (fixed)

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

czeky’s picture

Any ideas? looking for the same, have fivestar rating of the user profile using node_profile and want to display user profile rating on all nodes user created... thanx

Richard Blackborder’s picture

I'd use the devel module and the theme developer there to see which theme templates/functions you have access to and, if any of them have a $profile or $user or $account object, use that to print the Fivestar Extra form.

czeky’s picture

thanx.. solved here... http://drupal.org/node/344210

drecute’s picture

What I've noticed is that, outside from the user profile page, fivestarextra is unavailable. I was went ahead to enable fivestar rating on content profile, but fivestarextra still is unavailable.

I tested with the following code on node page:


global $user;
$uprofile = user_load(array('uid'=>$variables['account']->uid));
drupal_set_message(var_export($uprofile));

//This returns NULL
$nodeprofile = content_profile_load('profile', $uprofile->uid);
drupal_set_message(var_export($nodeprofile));
alexmoreno’s picture

for anyone looking for a solution, try:

$user = user_load($uid);
echo drupal_get_form('fivestarextra_form_comment_'. $comment->cid, 'comment', $comment->cid);