我想覆盖page.tpl.php来制作一个自定义登录页面。实际登录的 body 标签的类为:
<body class="html front not-logged-in one-sidebar sidebar-first page-customerror page-customerror- page-customerror-403 i18n-en">
如何覆盖 page.tpl.php 的新文件的名称?
我已经尝试过page--not-logged-in.tpl.php
,page-not-logged-in.tpl
,page-front-not-logged-in.tpl
但似乎没有任何效果。
每次更改文件名时,我也会刷新缓存,但什么也没发生。
您可以定义预处理函数
1) 添加您的template.php
function yourcustomtheme_preprocess_page($vars) {
global $user;
if ($user->uid ==0)) {
$vars['template_files'][] = 'page-not-logged';
}
}
2)现在,您可以使用page-not-logged.tpl.php
其他方式,您可以为所有用户使用相同的模板
编辑page.tpl.php
并添加
<?php
global $user;
if($user->uid ==0 ){
//Your code for anon users
}
else {
//Copy the original page.tpl here
}
?>
在主题的template.php
文件中
function [YOUR_THEME]_preprocess_page(&$vars) {
global $user;
if($user->uid < 1 && arg(0) == "user") {
$vars['theme_hook_suggestion'] = 'page-not-logged-in';
}
}