3

I'm trying to theme the login user page and it seems that I'm missing something and I can't figure out what it is.

here is what I did:

I've added this code to my template.php:

 function mxblog_theme() {
  $items = array();
  // create custom user-login.tpl.php
  $items['user_login'] = array(
  'render element' => 'form',
  'path' => drupal_get_path('theme', 'mxblog') . '/templates',
  'template' => 'page--user--login',
  'preprocess functions' => array(
  'mxblog_preprocess_user_login'
  ),
 );
return $items;
}

and this that I'm trying to render in the page--user--login.tpl.php

   print drupal_render($form['name']);
    print drupal_render($form['pass']);

    print drupal_render($form['form_build_id']);
    print drupal_render($form['form_id']);
    print drupal_render($form['actions']);
  • 1
    Can you define "missing something"? And what the objective is? – Kevin Aug 25 '16 at 14:36
  • I'm basically trying to achieve this : dannyenglander.com/blog/customizing-user-login-page-drupal-7 though 'user-login.tpl.php' isn't being recognize but 'page--user--login.tpl.php' is – Kitty77 Aug 25 '16 at 14:41
  • 1
    That's because you defined the template name above as page--user--login, and not user-login. – Kevin Aug 25 '16 at 15:05
  • Well I did try to set as user-login and no luck it doesn't display of the drupal-render at all (you can see the screenshot postimg.org/image/ldz7miaqj ) – Kitty77 Aug 25 '16 at 15:13
  • 1
    It sounds like you are on the right track but yes, as defined above, the template would be user-login.tpl.php. Did you clear all Drupal caches a few times? Where are you putting that template? Can you put a kpr function in the template to see what it prints out? – Danny Englander Aug 25 '16 at 15:22
1

When using page--user--login.tpl.php you have to manually fetch the user login form, as your overriding the entire page template not just the form.

You can either include this directly in the template (along with any other markup):

print drupal_render(drupal_get_form('user_login'));

Or in your mxblog_preprocess_user_login() function must return the form:

function mxblog_preprocess_user_login(&$variables){
  $variables['form'] = drupal_get_form('user_login');
}

then in the template you should be able to to do as you want:

print drupal_render($form['name']);
print drupal_render($form['pass']);
print drupal_render($form['form_build_id']);
print drupal_render($form['form_id']);
print drupal_render($form['actions']);
0

Thanks for your answers :) For those who are interested, here is what I did:

I created a user-login.tpl.php (note the single '-') and then I added a background image:

.page-user-login { position: fixed; left: 0; top: 0; width: 100%; height: 100%;

background: url('xxx/login_BG_rezised.jpg') no-repeat center center fixed; background-size: cover;

}

LES PROS DU BTP ONT LA PAROLE Votre média pour s'informer et communiquer.
<div class="login-page">

<form class="login-form">

<span class = "login-form-info"> Inscription rapide et GRATUITE. </span>
 <input type="text" placeholder="Nom utilisateur" name="name" id="edit-name" required="required" class="form-text required"/>
 <input type="password" placeholder="Mot de passe" name="pass" id="edit-pass" required="required" class="form-text required" />

<input type="hidden" name="form_id" id="edit-user-login" value="user_login"  />
<input type="submit" name="op" id="edit-submit" value="Connectez-vous" class="form-submit" />

<p class="message">Pas de compte? <a target="_blank" href="https://xxx/user/register">Créez votre compte</a></p>
<p class="message">Mot de passe oublié? <a target="_blank" href="https://xxx/user/password">Renvoyez le moi</a></p>

added some css style for the form to look the way I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.