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

标签 drupal-7

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

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

所以我想在使用此 View 模式时使用我的模块中包含的模板。

我的代码:

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

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

但是$vars['theme_hook_suggestions'][] = 'node_vacancy_teaser'; 在哪里?寻找模板文件?不知何故,它不包括/使用。

显然在 drupal 7 中出于某种原因需要使用双下划线。
放置在事件模板文件夹中的 node_vacatures_vacancy_teaser.tpl.php 似乎可以解决问题……尽管我认为这不是一个巧妙的解决方案,因为 tpl.php 文件与模块分离。

最佳答案

一定要在 hook_theme 实现中指定模板文件。 examples project非常适合了解如何执行此类操作的详细信息。具体来说,查看theming_example_theme() functiontheming_example module

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',
    ),
  );
}

关于drupal-7 - 我如何在我的模块drupal 7中包含一个tpl文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8242415/

相关文章:

drupal-7 - 使用 Drupal 规则向具有角色的用户发送电子邮件,但仅发送一次

drupal - Drupal 7 有没有办法阻止管理员编辑节点?

php - 如何使用添加更多选项在 Drupal 7 Ajax 表单中保留和检索图像详细信息?

css - iframe 的响应问题

php - 如何去除 Field Group 模块标签长度限制?

forms - Drupal 7 将表单保存到数据库

php - 如何在 Drupal 7 中管理预告片及其图像字段?

css - Drupal 7 CSS 问题

mysql - 从 {invalid_table} 中选择 invalid_field

Drupal Commerce - Paypal 即时付款通知警告