Templates Drupal7:如何为多种内容类型创建一个节点页面?
在我的网站中有8种内容类型,其中4种结构相同,不同的只是名称。我想为它们创建一个节点页面,但我想为每个节点创建一个.tpl.php文件效率很低。我使用以下方法为特定内容类型创建节点页面:Templates Drupal7:如何为多种内容类型创建一个节点页面?,templates,preprocessor,content-type,Templates,Preprocessor,Content Type,在我的网站中有8种内容类型,其中4种结构相同,不同的只是名称。我想为它们创建一个节点页面,但我想为每个节点创建一个.tpl.php文件效率很低。我使用以下方法为特定内容类型创建节点页面: 创建页面并将其重命名为page--node--Machine-Name-of-ContentType.tpl.php 将此函数添加到template.php 函数ThemeName_预处理_页面(&$variables) { } 有没有办法为多个内容类型创建一个节点页面 function theme_prepr
function theme_preprocess_page(&$vars) {
if (isset($vars['node']->type)) {
switch ($vars['node']->type) {
case 'news':
case 'blog':
case 'event':
case 'page':
$vars['theme_hook_suggestion'] = 'page__alt';
break;
}
}
将使用page--alt.tpl.php文件
function theme_preprocess_page(&$vars) {
if (isset($vars['node']->type)) {
switch ($vars['node']->type) {
case 'news':
case 'blog':
case 'event':
case 'page':
$vars['theme_hook_suggestion'] = 'page__alt';
break;
}
}