Nicola Peluchetti
Nicola Peluchetti

Reputation: 76870

Treat the node nids as a field (for display only in a content type) in drupal 7

I need to use the nid of a node as field in a content type: i need to choose where to print it (put it before some fields but after others) and format it as i wish. the only thing i could think about is create a "fake" custom field with no widget to insert it buth with a theme formatter to display it but it seems to me that this is a little to complicated. How should i do it?

Upvotes: 0

Views: 93

Answers (1)

Coder1
Coder1

Reputation: 13321

If I understand correctly, you just want to expose data to the node view. Could it be as easy as using hook_node_view() from a module?

With that, you can set a 'fake' field to be sent out to the content array of the node, which you can access in the node template.

From drupal.org:

<?php
function hook_node_view($node, $view_mode, $langcode) {
  $node->content['my_additional_field'] = array(
    '#markup' => $additional_field, 
    '#weight' => 10, 
    '#theme' => 'mymodule_my_additional_field',
  );
}
?>

Upvotes: 2

Related Questions