Модуль работает не так, как ожидалось


Я не могу понять, почему этот модуль не работает. Что в этом плохого?

/* hook_menu() */
function profilepage_menu() {
  $items['p'] = array(
    'title' => 'Profile page',
    'page callback' => 'profile_exe',
    'access callback' => TRUE,
    'type' => MENU_CALLBACK,
  );

  return $items;
}

/* Callback function */
function profile_exe($id) { 
  $ar = array('uid' => $id, 'profilesload' => profile2_load_by_user($id));

  return theme('profilebuild', array('collected' => $ar));
}

/* Custom theme function. */
function theme_profilebuild($variables) {
  return "";
}

/* hook_theme() */
function profilebuild_theme() {
  return array(
    'profilebuild' => array(
      'variables' => array('profilesload' => array()),
      'template' => 'profilepage',
    ),
  );
}

Модуль установлен, и страница называется profilepage.tpl.php находится в моем каталоге тем И в каталоге модулей.

Вывод, который я ожидаю, должен быть текстом в profilepage.tpl.php страница вместе с содержимым массива $variables, который я планирую использовать в своем шаблоне.

Однако, когда я открываю http://example.com/?q=p в моем браузере страница загружается без ошибок, но ожидаемого содержимого там нет.

Что я делаю не так?

 1
Author: kiamlaluno, 2011-06-04

1 answers

Проблема, которую я вижу в вашем коде, заключается в имени файла шаблона, который вы объявляете в своей реализации hook_theme(). Имя файла для файла шаблона должно быть идентификатором темы, используемым в качестве индекса массива в массиве, возвращаемом hook_theme() (в вашем случае "profilebuild"); если в идентификаторе используются подчеркивания, в имени шаблона следует использовать дефисы.

В качестве примера того, как называются файлы шаблонов, см. Следующие реализации hook_theme() для ядра Drupal модули.

function book_theme() {
  return array(
    'book_navigation' => array(
      'variables' => array('book_link' => NULL), 
      'template' => 'book-navigation',
    ), 
    'book_export_html' => array(
      'variables' => array('title' => NULL, 'contents' => NULL, 'depth' => NULL), 
      'template' => 'book-export-html',
    ), 
    'book_admin_table' => array(
      'render element' => 'form',
    ), 
    'book_title_link' => array(
      'variables' => array('link' => NULL),
    ), 
    'book_all_books_block' => array(
      'render element' => 'book_menus', 
      'template' => 'book-all-books-block',
    ), 
    'book_node_export_html' => array(
      'variables' => array('node' => NULL, 'children' => NULL), 
      'template' => 'book-node-export-html',
    ),
  );
}

function aggregator_theme() {
  return array(
    'aggregator_wrapper' => array(
      'variables' => array('content' => NULL), 
      'file' => 'aggregator.pages.inc', 
      'template' => 'aggregator-wrapper',
    ), 
    'aggregator_categorize_items' => array(
      'render element' => 'form', 
      'file' => 'aggregator.pages.inc',
    ), 
    'aggregator_feed_source' => array(
      'variables' => array('feed' => NULL), 
      'file' => 'aggregator.pages.inc', 
      'template' => 'aggregator-feed-source',
    ), 
    'aggregator_block_item' => array(
      'variables' => array('item' => NULL, 'feed' => 0),
    ), 
    'aggregator_summary_items' => array(
      'variables' => array('summary_items' => NULL, 'source' => NULL), 
      'file' => 'aggregator.pages.inc', 
      'template' => 'aggregator-summary-items',
    ), 
    'aggregator_summary_item' => array(
      'variables' => array('item' => NULL), 
      'file' => 'aggregator.pages.inc', 
      'template' => 'aggregator-summary-item',
    ), 
    'aggregator_item' => array(
      'variables' => array('item' => NULL), 
      'file' => 'aggregator.pages.inc', 
      'template' => 'aggregator-item',
    ), 
    'aggregator_page_opml' => array(
      'variables' => array('feeds' => NULL), 
      'file' => 'aggregator.pages.inc',
    ), 
    'aggregator_page_rss' => array(
      'variables' => array('feeds' => NULL, 'category' => NULL), 
      'file' => 'aggregator.pages.inc',
    ),
  );
}

Реализации этого крючка в Drupal 7 немного отличаются от реализации, выполненной в Drupal 6, но индекс "шаблон" используется одинаково в обеих версиях.

function block_theme() {
  return array(
    'block_admin_display_form' => array(
      'template' => 'block-admin-display-form', 
      'file' => 'block.admin.inc', 
      'arguments' => array('form' => NULL),
    ),
  );
}
 0
Author: kiamlaluno, 2011-06-27 01:02:29