1

In page.tpl.php I'm displaying a link for user page. For an example:

<?php echo l(t("My offers"), 'user/' . $user->uid . '/offers'); ?>

So when a user clicks on the link it goes to user/uid/offers.

Now I want to show this link only based on a role. Let's say we have a role "Seller" that has unique ID 5 in the database. How can I set

<?php echo l(t("My offers"), 'user/' . $user->uid . '/offers'); ?> 

to be visible only when a user has a role "Seller"?-

  • Related: drupal.stackexchange.com/a/70465/16495 – Mołot Jan 22 '14 at 15:41
  • It shows how to access $user in tpl. If you var_dump($user), you will see $user->roles. Come on, you can test variables on your own :D – Mołot Jan 22 '14 at 15:52
  • I've tested the code, but it didn't help. It only shows the array with details of the user. I didn't find how can I set link that will be visible only for a specific role. – user2519032 Jan 22 '14 at 19:00
2

I've got answer from drupal.org and this is the right solution:

<?php
if(isset($user->roles[5]))
{
  echo l(t("My offers"), 'user/' . $user->uid . '/offers');
}
1

For a non-coding method, you can create a block or for more control over the content a Views block that shows for certain roles.

0

you can do this in following way say your seller roll machine_name is profile_seller then,

<

?php
if($user->**profile_seller** == "yes")
{
  echo l(t("My offers"), 'user/' . $user->uid . '/offers');
}
?>

Let us know if it works

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.