在我主题的template.php文件中,我尝试了以下操作:
function media_preprocess_page(&$vars, $hook) {
if (isset($vars['node']))
{
// If the node type is "blog" the template suggestion will be "html--blog.tpl.php".
$vars['theme_hook_suggestions'][] = 'html__'.$vars['node']->type;
// If the node type is "blog" the template suggestion will be "page--blog.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'.$vars['node']->type;
// If the node id is "33" the template suggestion will be "page--33.tpl.php".
$vars['theme_hook_suggestions'][] = 'page__'.$vars['node']->nid;
}
//Create page suggestion for first part of url-alias
$url_alias = drupal_get_path_alias($_GET['q']);
$parts = explode('/', $url_alias);
$vars['theme_hook_suggestions'][] = 'page__'.$parts[0].'__alias';
}
这适用于page--nodetype.tpl.php,但不适用于html--nodetype.tpl.php
您可能会问为什么每个节点类型都需要覆盖html.tpl.php模板。这是因为我不想为此特定节点包括标记。