Customizing the login, registration and request password full page layout

Last modified: June 20, 2009 - 18:20

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

  1. make a copy of your page.tpl.php file and rename it to be page-login.tpl.php.
  2. Using a text editor like notepad.exe or equivalent, modify the layout of page-login.tpl.php file to suit your desires
  3. Upload your new page-login.tpl.php layout file to your active theme folder

Step 2 of 2

  1. Using a text editor like notepad.exe or equivalent, open your template.php file.
  2. If do not already have a _phptemplate_variables fuction in this file you can paste snippet version #1 into your file directly. If you already have a _phptemplate_variables function you will have to paste snippet version #2 into the function _phptemplate_variables.
  3. 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';
  }
}
?>

It does not work. Login form

Keyser - July 2, 2009 - 21:41

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.

 
 

Drupal is a registered trademark of Dries Buytaert.