0

I want to display a link on a node view page just like the "Add new comment" link. How should I do this?

I think it can be done through hook_node_view(), but how can I use this hook?

3
  • What do you mean "how can I use this hook"? You use this hook just like you use any other hook that your module implements: by implementing an appropriately named function and waiting for Drupal to call it.
    – Oswald
    Commented Sep 6, 2011 at 13:39
  • I have use the hook but nothing happens. Can you write code so that I match it with my code?
    – Ahmad
    Commented Sep 7, 2011 at 3:49
  • First of all, check whether your implementation of the hook is actually executed, e.g by calling drupal_set_message inside your hook implementation.
    – Oswald
    Commented Sep 7, 2011 at 8:43

3 Answers 3

1

In your implementation of hook_node_view(), add an element to the $node->content array. The element should be a renderable array as expected by drupal_render().

3
  • Can you provide me some code help?
    – Ahmad
    Commented Sep 7, 2011 at 3:50
  • Sure; you provide the code and I help by telling you what's wrong with it.
    – Oswald
    Commented Sep 7, 2011 at 8:36
  • Ok I solved the problem using hook_node_view.
    – Ahmad
    Commented Sep 7, 2011 at 9:28
1

In drupal6, you could implement the hook_links (just like the node module does http://api.drupal.org/api/drupal/modules--node--node.module/function/node_link/6)

2
0

Use hook_node_view and add new variable $node->my_link , add template file page--my_node.tpl.php and place that link wherever you want. This is solution for dynamic link for every node.

If you just want to add some no-dynamic link to your node_type than just add it in template file.

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