I'm looking for the equivalent of: page-user-login.tpl.php in Drupal 7 ( D7 ).

I'm looking to change or alter the layout of the user login page ( /user/login ), but more than just replacing values through hook_form_alter().
Any help is much appreciated!!

Comments

wOOge’s picture

Answered my own question:

In template.php place the following code, but replace "YOURTHEME" with... you theme name:

/**
* Registers overrides for various functions.
*
* In this case, overrides three user functions
*/
function YOURTHEME_theme() {
  return array(
    'user_login' => array(
      'template' => 'user-login',
      'variables' => array('form' => NULL), ## you may remove this line in this case
    ),
    'user_register' => array(
      'template' => 'user-register',
      'variables' => array('form' => NULL), ## you may remove this line in this case
    ),
    'user_pass' => array(
      'template' => 'user-pass',
      'variables' => array('form' => NULL), ## you may remove this line in this case
    ),
  );
}

function YOURTHEME_preprocess_user_login(&$variables) {
$variables['form'] = drupal_build_form('user_login', user_login(array(),$form_state)); ## I have to build the user login myself.
}

Then create a file called user-login.tpl.php and place it in your theme folder's root.

--
wOOge | adrianjean.ca

Sameo’s picture

And what I should to put into the user-login.tpl.php file?

info@cgfix.com’s picture

This only themes the form. Do you know how to do the whole page?

drupik’s picture

Just page--user--login.tpl.php

Danny Englander’s picture

I just wrote an entire blog post on this last week: http://highrockmedia.com/blog/customizing-user-login-page-drupal-7

It should give you everything you need.

new123456789’s picture

Once I've created a new template, how do I link it to the certain content types?

xbrianx’s picture

The solution in the blog worked well enough for my needs, but how do I edit the registration area?

xbrianx’s picture

Adding to the template.php of the theme, and creating a file called 'user-register-form.tpl.php'

function YOURTHEMENAME_theme() {
  $items = array();
  // create custom user-login.tpl.php
  $items['user_login'] = array(
  'render element' => 'form',
  'path' => drupal_get_path('theme', 'YOURTHEMENAME') . '/templates',
  'template' => 'user-login',
  'preprocess functions' => array(
  'YOURTHEMENAME_preprocess_user_login'
  ),);
  $items['user_register_form'] = array(
  'render element' => 'form',
  'path' => drupal_get_path('theme', 'YOURTHEMENAME') . '/templates',
  'template' => 'user-register-form',
  'preprocess functions' => array(
  'YOURTHEMENAME_preprocess_user_register_form'
  ),
);
return $items;
}
lionslair’s picture

Your link is broken has it moved somewhere else?

blogook’s picture

Whatever I try on my drupal 7 .. i cannot get the above to work. I am using Marinelli as my theme, but I also tried the above with Bartik and others that come with drupal.

Below is what i have in my template.php

/**
* Overrides of theme implementations
*/
function marinelli_theme() {

  return array(
    'custom_links' => array( // function that renders classic primary menu with <h2>
      'variables' => array('links' => NULL, 'attributes' => NULL, 'heading' => NULL),
    ),
    'mega_menu' => array(
      'variables' => array('menu' => NULL),
    ),
    'mbanner_text' => array(
      // 'variables' => array('text' => NULL),
    ),
    'mbanner_nav'  => array(
      'variables' => array('prev' => NULL, 'next' => NULL),
    ),

    'user_login' => array(
      'template' => 'user-login',
      'variables' => array('form' => NULL), ## you may remove this line in this case
    ),
    'user_register' => array(
      'template' => 'user-register',
      'variables' => array('form' => NULL), ## you may remove this line in this case
    ),
    'user_pass' => array(
      'template' => 'user-pass',
      'variables' => array('form' => NULL), ## you may remove this line in this case
    ),

  );
}

function marinelli_preprocess_user_login(&$variables) {
$variables['form'] = drupal_build_form('user_login', user_login(array(),$form_state)); ## I have to build the user login myself.
}

I have the folling file in my themes/marinelli/templates/ folder

page--user-login.tpl.php

I aso tried with

user-lgin.tpl.php

but it still loads my page.tpl.php page. As a workaround I have in my page.tpl.php

<?php
   
    
if (!$user->uid) { //check to see if the user is logged in. If not display the special login page layout
   
?>

Not the solution I am looking for :(

drupik’s picture

See http://drupal.org/node/1089656 - "How Drupal determines page theme hook suggestions based on path".
Just use page--user--login.tpl.php if you accessing path like yourdomain.com/user/login, if you want yourdomain.com/user, use page--user.tpl.php without any additional code in template.php file.

Dropal’s picture

Brutal! :D
Thanks.

Dropal’s picture

I see so much trouble for simple things. I just scrolled for a bunch of posts how to theme the "Login Page" but actually people are theming the login block, imitating each other posts all over their blogs and websites.

Do you want to achieve a minimal designed and beautiful page like this?
Login page: http://s10.postimg.org/42qaumbbt/login.png
Password page: http://s22.postimg.org/lv2psotsh/password.png

1 )
Create the login and password empty page files and place them in your theme "templates" folder.
The name of the files are page--user--login.tpl.php and page--user--password.tpl.php. There's no need of all those steps of "hook", "alter", blablabla... Drupal will use those files automatically without any call or whatever.

2 )
Put this code inside your files.

page--user--login.tpl.php

<?php print $messages; ?>

<?php print drupal_render(drupal_get_form('user_login')); ?>
<a href="user/password">Request new password"</a>

page--user--password.tpl.php

<?php print $messages; ?>

<?php print drupal_render(drupal_get_form('user_pass')); ?>
<a href="user/login">Go back</a>

3 )
Done!
In thee steps. Now style your css as much you need and pimp your new fancy login page. "Inspect" your html output of your new login page and see how clean it is now. ; D

Afterwords )
I just spent this last hour reading posts and questions about this all over the internet, and the work around in some cases are simply crazy like using the dpm(get_defined_vars()); function, copying html and paste all of those input forms and attributes, blablabla.
I didn't found a concise post like this. It's crazy!!!

Also, you will need (if you still don't have it and if you want it) to disable "label/description" and enable "placehover" for the inputs. You can do it all together like this:

<?php
/*
 *  Remove labels and add HTML5 placeholder attribute to login form
 */
function THEMENAME_form_alter(&$form, &$form_state, $form_id) {
  if (
TRUE === in_array( $form_id, array( 'user_login', 'user_login_block') ) )
   
$form['name']['#attributes']['placeholder'] = t( 'Username' );
   
$form['pass']['#attributes']['placeholder'] = t( 'Password' );
   
$form['name']['#title_display'] = "invisible";
   
$form['pass']['#title_display'] = "invisible";
}



/*
 *  Remove login form descriptions
 */
function THEMENAME_form_user_login_alter(&$form, &$form_state) {
   
$form['name']['#description'] = t('');
   
$form['pass']['#description'] = t('');
}
?>

PS )
Do you have the "header", "footer" and "sidebar" visible and want to remove them too? No problem.
Go to #overlay=admin/structure/block and click "configure". Scroll down and include this on "Show block on specific pages" option:

user/login
user/password

Done!
Drupal it's incredible powerful. I think people complicate things a lot and if you see it in a simple way it will be more efficient... Most of the things you can do it inside Drupal environment.

techTD’s picture

Dropal's idea works but a warning msg is displayed at the top of the page.

Error messageStrict warning: Only variables should be passed by reference in include() (line 3 of ....templates/page--user--login.tpl.php).

Anyone has any idea what its telling?

TD

usta’s picture

That's because drupal_get_form is nested inside drupal_render.

Hence replace:

<?php print drupal_render(drupal_get_form('user_login')); ?>

With:

<?php
  $form
= drupal_get_form('user_login');
  print
drupal_render($form);
?>
sjhuskey’s picture

The template file at http://dannyenglander.com/blog/customizing-user-login-page-drupal-7 saved the day for me. It helped me find the variables that I needed to change.