drupal 7 模版文件templates.php的一点使用经验及小结
1:在drupal里面,page.tpl.php默认是没有根据content type来定制模版的。如果想根据content type定制模版怎么办?很简单。
找到当前主题下的template.php文件。一般的主题都有。如果没有,请创建。加入下面的代码:
function THEMENAME_preprocess_page(&$variables, $hook) {
if (!empty($variables['node'])) {
$node = $variables['node'];
$variables['theme_hook_suggestions'][] = 'page__type__' . $node->type;
}
}
注意一下,一定要用下划线。
写完,新建一个page--type--yourtype.tpl.php文件,就可以使用这个模版来控制yourtype的输出了。