2

I'm using EntityFieldQuery to get node IDs that match certain criteria in my module. At the end, I am doing: return node_view_multiple($nodes, 'full'); in the page callback function (which itself is called from hook_menu).

If I use node--content-type.tpl.php, I override the display everywhere. Ideally, I would like an array containing Node information that is sent to the tpl file, (like a controller returning display array to a view in CodeIgniter), which I can loop through and create a custom display.

How do I go about this?

1

Instead of doing a full node view you can make a custom node view like

return node_view_multiple($nodes, 'module_name');

That will enable you to create custom logic for this view type and setup field display as well if needed.

To define your own view mode you need to add it using hook_entity_info_alter

/**
 * Implements hook_entity_info_alter().
 */
function hook_entity_info_alter(&$entity_info) {
  $entity_info['node']['view modes']['module'] = array(
    'label' => t('Name'),
    'custom settings' => TRUE,
  );
}
  • Thank you for answering - from the point of defining my own node view, how do I get to theming that view with a tpl file? – Aditya M P Apr 2 '12 at 10:12
  • @adityamenon You can add logic to the same template and handle the different view modes by doing if ($view_mode == '...'), or you could add template suggestions based on the view mode in the preprocess_node hook. – googletorp Apr 2 '12 at 11:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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