1

I'm trying to add the user login block in my page.tpl file. I've tried inserting the following code but the only thing I see is the username, password and submit fields. The "Register" and "Forgot your Password" fields are not there. And I would like to do this in code form. Cause I wanna put the user login block in a specific place.

if(!user_is_logged_in() ){
    $userLoginForm = drupal_get_form('user_login');
    print drupal_render($userLoginForm);
}

Thanks :)

1
  • Don't do it. Go to /admin/structure/block and place "User login" block in region you want.
    – Mołot
    Sep 18, 2014 at 8:21

1 Answer 1

-1

you can do it like this:

$block = block_load('user', 'login');
$block = _block_render_blocks(array($block));
$block_build = _block_get_renderable_array($block);

print drupal_render($block_build);

this will generate a block with title and contexual links also..

7
  • I think it is a bad thing to do. Template should never need particular blocks available. Proper way would be to render a region, and use admin interface to put a block in that region.
    – Mołot
    Sep 18, 2014 at 8:22
  • @Mołot I know, I answered his/her previuos question, read the comments, please..
    – xurshid29
    Sep 18, 2014 at 8:24
  • @Mołot this can be done in TEMPLATE_preprocess_page function, not in tpl file..
    – xurshid29
    Sep 18, 2014 at 8:26
  • Actually, comments are "second-class citizens", if something is not in question or answer, it is next to non-existent. And it seems OP is coding against environment and nobody bothered to tell him, you just guide him deeper into problems and hard to manage solutions.
    – Mołot
    Sep 18, 2014 at 8:27
  • @Mołot I am not trying to teach him, I'm just answering the question, I don't think drupal.stackexchange.com is a tutorial site, and also he is not asking how to properly assign a block to region
    – xurshid29
    Sep 18, 2014 at 8:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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