3

I'm trying to render nodes with a custom view mode, having another tab for each node in the same place than "Edit", "View", etc. So I have declared my custom view mode with hook_entity_info_alter, my new "tab" with hook_menu, with a page_callback pointing to a custom function that should return the node according to my custom view node. It works great, but the node title is rendered too. How can I remove the node title ? Here is the code. Thanks!

   /**
   * Implements hook_entity_info_alter().
   */
   function test_custom_view_mode_entity_info_alter(&$entity_info) {
     $entity_info['node']['view modes']['another_teaser'] = array(
       'label' => t('Another teaser'),
       'custom settings' => TRUE,
     );
   }

   /**
   * Implements hook_menu().
   */
   function test_custom_view_mode_menu()
   {      $items['node/%node/another-teaser'] = array(
           'title' => 'Another Teaser',
           'page callback' => '_test_custom_view_mode_display_content',
           'page arguments' => array(1),
           'access arguments' => array('access content'), 
           'type' => MENU_LOCAL_TASK,
       );   

          return $items;
   }
   /**
   * Custom page callback hook_menu().
   */

   function _test_custom_view_mode_display_content($node) {
     $node_viewed = node_view(node_load($node->nid), 'another_teaser');

     return array(
              'content' => array(
                'node' => $node_viewed,
              ),
            );
   }
  • Are you sure it's the node title and not the page title (i.e. from page.tpl.php) that's showing? – Clive Jul 5 '13 at 15:30
  • 1
    Thanks Clive ! I didn't thought about it. I just add to template_preprocess_node this code snippet: if($vars['view_mode'] == 'another_teaser') { $vars['title'] = ''; } – Franperr Jul 5 '13 at 16:39
  • Variable name $node_rendered is misleading as it has not actually been rendered at this point. Better would be $node_view or $node_render_array or something like that. – Kari Kääriäinen Jan 28 '16 at 7:42
  • you're right, I changed it – Franperr Jan 28 '16 at 11:49
1

I think you need to render send the element as html out put since there is no any theme function defined. See how this output process here.

So your return array should be:

 return array(
          '#markup' => $node_rendered
        );

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.