Skip to content

Instantly share code, notes, and snippets.

@danreb
Created October 8, 2012 02:41
Show Gist options
  • Save danreb/3850448 to your computer and use it in GitHub Desktop.
Save danreb/3850448 to your computer and use it in GitHub Desktop.
Drupal 7 code snippets for customizing user login and creating custom template file
http://drupal.org/node/350634
http://highrockmedia.com/blog/customizing-user-login-page-drupal-7
/*
* Implements hook_theme().
*
*/
function THEMENAME_theme() {
$items = array();
// create custom user-login.tpl.php
$items['user_login'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'THEMENAME') . '/templates',
'template' => 'user-login',
'preprocess functions' => array(
'THEMENAME_preprocess_user_login'
),
);
return $items;
}
<?php //print the variables if needed to allow for individual field theming or breaking them up.
/*
print '<pre>';
print_r($variables);
print '</pre>';
*/
?>
<div class="THEMENAME-user-login-form-wrapper">
<div class="login-wrapper">
<h2><?php print render($intro_text); ?></h2>
<?php
// split the username and password from the submit button so we can put in links above
print drupal_render($form['name']);
print drupal_render($form['pass']);
?>
<div class="user-links">
<span class="passlink">
<a href="/user/password">Forget your password?</a></span> | <span class="reglink"><a href="/user/register">Create an account</a>
</span>
</div>
<?php
print drupal_render($form['form_build_id']);
print drupal_render($form['form_id']);
print drupal_render($form['actions']);
?>
</div><!--//login-wrapper-->
<!--- // Example, adding a photo
<div class="login-photo">
<img src="<?php print base_path() . drupal_get_path('theme', 'THEMENAME') . '/images/login-photo.jpg'; ?>" alt="Login" title="Login" width='327' height='221' />
</div>
-->
</div><!--//THEMENAME-user-login-form-wrapper -->
@danreb
Copy link
Author

danreb commented Oct 8, 2012

Note: Replace THEMENAME with the name of your theme. The file user-login.tpl.php will be placed inside the folder named templates.

@danreb
Copy link
Author

danreb commented Oct 8, 2012

replace THEMENAME with the name of your theme, put user-login.tpl.php inside templates folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment