Созонов Алексей

Веб-разработчик

Свой node view

25.08.2015

Чтобы создать свое представление для ноды, нужно добавить:

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

и

/**
* Implements hook_preprocess_node().
*/
function MYMODULE_preprocess_node(&$vars) {
  if($vars['view_mode'] == 'another_teaser') {
    $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__another_teaser';
  }
} 

для создания произвольного файла шаблона. После чего, его название будет - node–article–another-teaser.tpl.php

#Drupal