I've searched the forums and googles, but can't seem to find the drupal 7 equivalent of the drupal 6 user-login.tpl.php. I tried user--login.tpl.php to no avail. How do I theme the login page?

Comments

julia_g’s picture

Have you found this out? I've had user-login.tpl.php in Drupal 6, and it's still working in Drupal 7, but the form itself is not showing up.

prat0318’s picture

I tried many drupal 6 tutorials for custom login ... but drupal_render($form) gives a blank page everytime. Please help.

aangel’s picture

Drupal won't find those files if you don't register them in a hook_theme() function:

/*
 *  Implements hook_theme().
 */
function HOOK_theme() {
  return array(
    'user_register_form' => array(
      'arguments' => array('form' => NULL),
      'template' => 'user-register',  // exclude the tpl.php
    ),
    'user_login' => array(
      'arguments' => array('form' => NULL),
      'template' => 'user-login',  
    ),
    'user_pass' => array(
      'arguments' => array('form' => NULL),
      'template' => 'user-password',  
    ),
  );
}

For more on this function see the API documentation.

To theme the pages, I had to use a total hack because I couldn't get D7 to see my template suggestions. This is NOT the way to do it but until I have more time to sleuth this in D7 it will have to do the job. I put it at the very top of page.tpl.php.

switch ($_GET['q']) {
case 'forum':
  include 'page--forum.tpl.php'; return;
  break;
  
case 'user/login':
  include 'page--user-login.tpl.php'; return;
  break;

case 'user/register':
  include 'page--user-register.tpl.php'; return;
  break;  

case 'user/password':
  include 'page--user-password.tpl.php'; return;
  break;  
}
medenfield’s picture

Here is the way I usually go with:

Step 1, register user-login.tpl.php in template.php like so (where hook is the name of your theme):

function hook_theme($existing, $type, $theme, $path){
  return array(
    'user_login' => array(
      'render element' => 'form',
      'template' => 'user-login', 
    ),
  );
}

Next, create a preprocess function that will let you modify the available variables from the output of the user module. This goes in your template.php file anywhere below the above function:

function hook_preprocess_user_login(&$variables) {

}

Now, create your user-login.tpl.php page in your theme folder. Simply put the following code at the top:

print '<pre>';
print_r($variables);
print '</pre>';

Clear your cache. On your next visit to /user/login you should see the array dumped out.

julia_g’s picture

medenfield - I've done this and variables look good. Now I try to actually render the form in user-login.tpl.php:
print drupal_render($variables['form']);
and this gives me white screen and "out of memory" error. Is there anything I'm missing here?

Ludo.R’s picture

I have the same issue WSOD when rendering form.

Any solution?

Connoropolous’s picture

This is for future comers benefit. You can find the proper procedure start to finish for drupal 7 here at this drupal node: http://drupal.org/node/350634

The key thing I think was this:

<?php print drupal_render_children($form) ?>

Gil_Gamesh’s picture

Thank you!!!

choitz’s picture

Fairly straight forward solution:
http://www.victheme.com/blog/drupal-7-creating-horizontal-login-bar-with...

Both functions go into template.php while print login_bar (); works in page.tpl.php.

Hopefully will stop you having to try various more complex methods.