3

I've removed the tabs 'view and edit' from the node content type display. I need to provide a custom link to edit the particular node based on user permissions. I've used node/%/edit in node tpl but it does'n't work. Can someone help me with the proper method to achieve this

5

In your node.tpl.php you have access to current node object $node and you can get the node id. You can check permissions for current logged user with user_access function

So you can do the next thing in your node.tpl.php

<?php 
      if (user_access('your_permission_here')){
       //create link for current node edit
       echo l(t('Edit this node'), 'node/' . $node->nid . '/edit');
      }
?>
2
  • You also need to check if the user is the author then render the edit link, otherwise anyone with the exact set of permission can see the link.
    – Sohail
    Jul 25 '15 at 11:42
  • Here is a better solution that checks the permission first: stackoverflow.com/a/33258230/1127583
    – batigolix
    Oct 21 '15 at 11:40
3

This did it for me without having to worry about user permissions(default drupal permissions apply)... pasted it in the tpl for getting the edit link.

<?php
if (node_access('update',$node)){
print l(t('Edit'),'node/'.$node->nid.'/edit' );
}
?>

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.