Drupal link function l() magic!

Public

Node links

</> CopyGet raw version
php
  1. // Node link
  2. print l('View' . $node->title, 'node/' . $nid);
  3.  
  4.  
  5. // Node Edit link
  6. print l('Edit ' . $node->title, 'node/' . $nid . '/edit');
  7.  
  8. // Delete Node link
  9. print l('Delete ' . $node->title, 'node/' . $nid . '/delete');

User links

</> CopyGet raw version
php
  1. // User link
  2. global $user;
  3. print l('User' . $user->name, 'user/' . $user->uid);
  4.  
  5.  
  6. global $user;
  7. print l('Edit ' . $user->name, 'user/' . $user->uid . '/edit');
  8.  
  9. // Redirect to user page after user edit profile
  10. global $user;
  11. print l('Edit ' . $user->name, 'user/' . $user->uid . '/edit', array(
  12. 'query' => array(
  13. 'destination' => 'user',
  14. ),
  15. ));

Complex links with lots of markup and other options.

</> CopyGet raw version
php
  1. // Link with lots of html as the link text (link to user profile)
  2. $user = user_load($uid);
  3. $output = '
  4. <div class="row">
  5. <div class="col-sm-12">
  6. <div class="thumbnail">
  7. <img src="' . base_path() . drupal_set_path('theme', 'MYTHEMENAME') . 'img/default_user.png" />
  8. <div class="caption">
  9. <h4>' . $user->name . '</h4>
  10. </div>
  11. </div>
  12. </div>
  13. </div>
  14. ';
  15. print l($output, 'user/' . $user->uid, array(
  16. 'html' => 'true',
  17. ));
  18.  
  19. // Link with just about everything in it
  20. print l('<i class="fa fa-user"></i> ' . $user->name, 'user/' . $user->uid . '/edit', array(
  21. 'html' => 'true',
  22. 'query' => array(
  23. 'destination' => current_path(), // takes you back to wherever you were when you send the link
  24. 'name' => $user->name, // sets a $_GET['name'] var when on the edit page
  25. 'message' => 'Saved yo!',
  26. ),
  27. 'attributes' => array(
  28. 'class' => array(
  29. 'btn',
  30. 'btn-lg',
  31. 'btn-primary',
  32. 'btn-block',
  33. ),
  34. ),
  35. ));