I'm working in Drupal 7 and using the reference module to attach an node reference to another node. I'm then using views to show some of that nodes fields. When I display the field for the node reference, I'm give the choice of formatting it as a title, title with link, or rendering out the whole node. All I really want to be able to do is render out the nid or the node rather than the title. There were a number of modules that did this in Drupal 6, anyone know how to do it in Drupal 7?


  • I was glad to find your post. Actually, this is exactly what I'm looking for. Would be pleased to see your patch.
    – user2976
    Sep 15, 2011 at 17:35

2 Answers 2


having trouble creating the patch, here is what I did, added

'node_reference_nid' => array(
  'label'       => t('Nid'),
  'description' => t('Display the nid of the referenced node.'),
  'field types' => array('node_reference'),

to the node_reference_field_formatter_info() function also added

  case 'node_reference_nid':
  foreach ($items as $delta => $item) {
    if ($item['access']) {
      $node = $item['node'];
      $result[$delta] = array(
          '#markup' => check_plain($node->nid),
      if (!$node->status) {
        $result[$delta]['#prefix'] = '<span class="node-unpublished">';
        $result[$delta]['#suffix'] = '</span>';

to the node_reference_field_formatter_view() function

that's it, hope it helps


Found a way to do this by altering the node_reference module within the references module. If anyone is interested in the patch let me know

  • You're encouraged to answer your own questions here. You should post a link to patch, write how you solved the problem, and mark the question as solved for future readers.
    – Shawn Conn
    May 22, 2015 at 15:52

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.