I am working on a node type which contains node references to other types. I want to programmatically duplicate a few node reference fields based on a set of conditions during rendering of the node. I have not been able to figure that out.

  • duplicate in what way? have them displayed in multiple places?
    – Jimajamma
    Nov 9, 2013 at 3:18
  • Yes multiple places on the same node. This is for printing purposes
    – Binny
    Nov 9, 2013 at 3:36

1 Answer 1


You have total control over the layout of nodes within your theme via the node.tpl.php file and its variants and overrides. Check out a lot of information about node.tpl.php here and template files in general here.

By creating a specific template, you can customize it to your purposes along these lines:

function YOURTHEME_preprocess_node(&$vars) {

  if ( /* whatever condition you have that returns true for printing */ ) {

  // any other node preprocessing goes here


Then, you put a node-printing.tpl.php file in your theme directory next to the default node.tpl.php for your theme, and in there, customize it as you like.

The key variables to be looking at are $content and $node. If you goto admin/content/node-type/NODE_TYPE/display on your system you can see how $content is built and customized, while the latter is it as an object containing all of its fields that you can rework and so forth.

Putting a drupal_set_message('<pre>' . print_r($node, TRUE) . '</pre>'); at the top of your new template file will show you what you have to work with.

And, as always, just remember to clear caches after creating this new template so that the theme registry picks it up, but now you should be able put anything anywhere you want in your node display.

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.