0

I want to add extra fields when a node is displayed, the data of this fields are fetched from an external db.

I'm uncertain if I've to use the hook_node_view_alter function or hook_node_view.

2 Answers 2

1

I don't understand if the extra fields to add are in the node form or into the page(display of node). If it's the first thing I think you can use hook_form_alter to add the extra fields and in the second case you can use hook_preprocess_node to add the variables to 'send' to the front-end of site.

2
  • It's the second case, so I understand that the hook_preprocess_node is the right function
    – alez
    Mar 2, 2015 at 7:52
  • However, I'm using hook_node_view and it seems effective
    – alez
    Mar 2, 2015 at 8:09
0

You could use hook_preprocess_node and add variables that you could use in a node template.

2
  • I'm using hook_node_view and it works, what is the advantage in using hook_preprocess_node?
    – alez
    Feb 27, 2015 at 18:37
  • If you've got it working, I'd say it's a matter of preference. No real advantage either way. With hook_node_view, you add fields to the node object. With hook_preprocess_node, you can add variables for direct use in the template. Feb 27, 2015 at 18:57

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.