Last updated January 3, 2011. Created by Dublin Drupaller on June 23, 2007.
Edited by mortona2k, NonProfit, bekasu, bryan kennedy. Log in to edit this page.
description
This snippet allows you to load a custom layout file and override the login, request password and registration page.
usage
Useful if you want to have a stand alone login page, for example.
Step 1 of 2
- make a copy of your page.tpl.php file and rename it to be page-login.tpl.php.
- Using a text editor like notepad.exe or equivalent, modify the layout of page-login.tpl.php file to suit your desires
- Upload your new page-login.tpl.php layout file to your active theme folder
Step 2 of 2
- Using a text editor like notepad.exe or equivalent, open your template.php file.
- If you do not already have a
_phptemplate_variablesfunction in this file you can paste snippet version #1 into your file directly. If you already have a_phptemplate_variablesfunction you will have to paste snippet version #2 into the function_phptemplate_variables. - Upload your edited template.php file to your active theme folder and your new layouts will take effect automatically
Snippet version #1
<?php
/**
* This snippet loads a custom page-login.tpl.php layout file when
* users click through to the login, request password or register pages
*/
function _phptemplate_variables($hook, $variables = array()) {
switch ($hook) {
case 'page':
global $user;
if (arg(0) == 'user'){
if (!$user->uid) { //check to see if the user is logged in. If not display the special login page layout
$variables['template_file'] = 'page-login';
}
elseif (arg(1) == 'login' || arg(1) == 'register' || arg(1) == 'password' ) {
$variables['template_file'] = 'page-login';
}
}
break;
}
return $variables;
}
?>Snippet version #2
This version of the snippet goes inside an existing _phptemplate_variables function that already has a return $variables statement.
<?php
global $user;
if (arg(0) == 'user'){
if (!$user->uid) { //check to see if the user is logged in. If not display the special login page layout
$variables['template_file'] = 'page-login';
}
elseif (arg(1) == 'login' || arg(1) == 'register' || arg(1) == 'password' ) {
$variables['template_file'] = 'page-login';
}
}
?>
Comments
It does not work. Login form
It does not work. Login form still the same. I have created a file page-login.tpl.php, added there just a single text for example "asdad", then added a function _phptemplate_variables and login form still default.
Mess with the best - die like the rest
I think this is because
I think this is because phptemplate isnt used in D6. I can find ways of using nodes for user registration, but I too want to replace the whole page. Is there a new method of doing this?
Drupal 6
I called my login file "page-user.tpl.php" instead of "page-login.tpl.php" and it works perfectly fine:)
If i want to separate login, register and password pages, i create three new copies of the original "page.tpl.php" file in my theme folder. In my case the zen-classic theme. I call them "page-user.tpl.php" (login), "page-user-register.tpl.php" (register) and "page-user-password.tpl.php" (new password). Inside each of the files i remove the following peace of code:
<?php endif; ?><?php if (!empty($tabs)): ?>
<div class="tabs"><?php print $tabs; ?></div>
<?php endif; ?>
This stops Drupal from showing the typical tabs in the "Login, Register and Password" section.
Hope that helps someone. Took me a while to figure it out:)
Changing it to
Changing it to "page-user.tpl.php" then allows those changes to appear on all pages under "user". How can I avoid this?
By doing something like
By doing something like this
<div id="content-area"><?php print $content; ?>
<?php if ($user->uid): ?>
HEY I'M LOGGED IN!
<?php elseif (arg(1)=='register'): ?>
HEY I'M ON REGISTER PAGE!
<?php elseif (arg(1)=='password'): ?>
HEY I'M ON FORGOT PASSWORD PAGE!
<?php else: ?>
HEY I'M ON LOG IN PAGE!
<?php endif; ?>
</div>
-
The first line containing
<?php endif; ?>from honorfield should be omitted. That belongs to the if statement above this snippet.----
http://picxelplay.com
"So Say We All"- Adama
.
If you're using Drupal 6, here's a link that does work:
http://www.caspianit.co.uk/drupal-6-custom-login-form/
not for me :)
not for me :)
-
I was sick of finding tutorials that just plain don't work, so I created a tutorial to theme the Register/Login/Password (Pages), not just the forms.
http://picxelplay.com/blog/theming-drupal-6-registration-login-and-reque...
----
http://picxelplay.com
"So Say We All"- Adama
Worked perfectly, piece of
Worked perfectly, piece of cake first time.
for D7 on Zen?
anyone got in for D7 on Zen?
It is not working for me, I
It is not working for me, I am using marinelli for my theme.