Drupal 7 如何在模块drupal 7中包含tpl文件
我正在使用hook_preprocess_node()构建一个模块 我使用hook\u entity\u info\u alter()为节点实体创建了一个新的视图模式,名为“空缺挑逗” 这将显示在“我的节点显示设置”和“视图”中 因此,在使用此视图模式时,我希望使用模块中包含的模板 我的代码:Drupal 7 如何在模块drupal 7中包含tpl文件,drupal-7,Drupal 7,我正在使用hook_preprocess_node()构建一个模块 我使用hook\u entity\u info\u alter()为节点实体创建了一个新的视图模式,名为“空缺挑逗” 这将显示在“我的节点显示设置”和“视图”中 因此,在使用此视图模式时,我希望使用模块中包含的模板 我的代码: /** * Implements hook_preprocess_node(). */ function vacancies_preprocess_node(&$vars) { if($var
/**
* Implements hook_preprocess_node().
*/
function vacancies_preprocess_node(&$vars) {
if($vars['view_mode'] == 'vacancy_teaser') {
$vars['theme_hook_suggestions'][] = 'node_vacancy_teaser';
}
}
我的模板文件名为:''node example striser.tpl.php',但未在我的视图的输出中使用
$vars['view\u mode']=='emptance\u striser'
在视图中。(测试)
但是,$vars['theme\u hook\u suggestions'][]='node\u business\u triser'在哪里代码>查找模板文件?不知怎的,它没有被包括/使用
显然在Drupal7中,出于某种原因需要使用双下划线。
放置在活动模板文件夹中的node_vacations_emptance_triser.tpl.php似乎起到了作用。。。尽管我认为这不是一个好的解决方案,因为tpl.php文件与模块是分开的。请确保在hook_主题实现中指定模板文件。这对于了解如何做这样的事情的细节非常有用。具体来说,请查看
不要在$vars['theme\u hook\u suggestions']
数组的末尾追加内容,请尝试:
数组_unshift($vars['theme\u hook\u suggestions'],'node\u unshift\u trister');
这会将您的建议传递到阵列的前端,并首先找到它。最有可能的是,由于您要将其附加到数组的末尾,Drupal首先会找到一个现有的主题建议,并使用它(例如node.tpl.php)。因此,为了清楚起见,您建议我使用hook\u主题,而不是hook\u preprocess\u node()并添加一个主题\u钩子\u建议?是的,经过3天的搜索,您发现了这个问题
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',
),
);
}