我如何在我的模块drupal 7中包含一个tpl文件

FLY*_*FLY 4 drupal-7

我正在使用hook_preprocess_node()构建模块我使用hook_entity_info_alter()为名为'vacancy_teaser'的节点实体创建了一个新的视图模式

这显示在我的节点显示设置和视图中

因此,当使用此视图模式时,我想使用模块中包含的模板.

我的代码:

/**
* Implements hook_preprocess_node().
*/
function vacancies_preprocess_node(&$vars) {
  if($vars['view_mode'] == 'vacancy_teaser') {
    $vars['theme_hook_suggestions'][] = 'node_vacancy_teaser';
  }
} 
Run Code Online (Sandbox Code Playgroud)

我的模板文件名为:'node-vacancy-teaser.tpl.php',但未在视图$vars['view_mode'] == 'vacancy_teaser'的视图输出中使用 .(测试过)

但在哪里$vars['theme_hook_suggestions'][] = 'node_vacancy_teaser';寻找模板文件?不知怎的,它没有被包含/使用.

显然在drupal 7中由于某种原因需要使用dubble下划线.node_ vacatures _vacancy_teaser.tpl.php放置在活动模板文件夹,似乎这样的伎俩......虽然我不认为这是因为tpl.php文件从模块分离纯溶液.

Mat*_* V. 7

请务必在hook_theme实现中指定模板文件.该示例项目是伟大的找出如何做这样的事情的细节.具体来说,检查出theming_example_theme()函数theming_example模块 ...

function theming_example_theme() {
  return array(
    // …
    'theming_example_text_form'  => array(
      'render element' => 'form',
      // In this one the rendering will be done by a tpl.php file instead of
      // being rendered by a function, so we specify a template.
      'template' => 'theming-example-text-form',
    ),
  );
}
Run Code Online (Sandbox Code Playgroud)