1

This maybe a dumb question but what am I doing wrong?

From here: https://www.drupal.org/node/942014

It says I have to insert:

if (module_exists('user_badges')) { print user_badges_for_uid($uid); }

When I insert that on the last line of my node.tpl.php it just shows as Text (like the whole code shows on the website). What am I doing wrong??

Can someone please help me?

1
  • PHP needs to be wrapped in <?php ... ?>
    – Clive
    Commented Mar 1, 2018 at 20:06

1 Answer 1

1

The first thing that you need to do is add the php tag to the code:

<?
if (module_exists('user_badges')) {
 print user_badges_for_uid($uid);
}
?>

But for to that this code works you need to pass the uid = User Id

This code should do the job:

<?
// Getting the actual user.
global $user;

if (module_exists('user_badges')) {
 print user_badges_for_uid($user->uid);
}
?>
4
  • @GrahamMiranda if the code works for you don't forget to check the answer as accepted, this can help other users to find the correct answer, if you don't know how, please check the Tour -> drupal.stackexchange.com/tour Commented Mar 1, 2018 at 20:16
  • @GrahamMiranda Good luck with your projects ;-) Commented Mar 1, 2018 at 20:32
  • Hey a quick question. I've uploaded this and it works for "My Badges" do you know how can I change the code to show people's profile badges? When I put the code on their profile it shows the user who's logged in badges. Commented Mar 3, 2018 at 3:53
  • @GrahamMiranda you need to get the uid of the user profile. You can open another question about this if you don't know how. Commented Mar 3, 2018 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.