The Drupal version I'm using is v7.34. I'm using sub-theme created from Bootstrap as base theme. My problem is, I want to override the "User Login Block" and put it in the header region (top bar), so I create these file in templates folder in my sub-theme:

  1. page.tpl.php

    //this simply do print render($page['header']);

  2. region--header.tpl.php

    $search_block = module_invoke('search', 'block_view', 'search'); $login_block = module_invoke('user', 'block_view', 'login'); print render($search_block); print render($login_block);

  3. search-block-form.tpl.php

    //this copied from base theme and only modified some html tag

  4. block--user--login.tpl.php

    //this simply print out some simple text print ("blahhhhhhhhhhhhhh");

The result is, only search block is rendered as override, and the login block is rendered as default block, not rendered as the one I override. I did some search but nothing matches my fault.

  • Did you clear your cache? Nov 21, 2014 at 5:33

1 Answer 1


To Alter User login block

  • Find the template.php file for the theme you're working on. Should be in the root of the theme folder for your theme
  • Assuming the "yourthemename_hook" function does NOT exist, at the bottom of your template.php file insert the following code:
function yourthemenamehere_theme(&$existing, $type, $theme, $path) {
   $hooks['user_login_block'] = array(
     'template' => 'templates/user-login-block',
     'render element' => 'form',
   return $hooks;
function yourthemenamehere_preprocess_user_login_block(&$vars) {
  $vars['name'] = render($vars['form']['name']);
  $vars['pass'] = render($vars['form']['pass']);
  $vars['submit'] = render($vars['form']['actions']['submit']);
  $vars['rendered'] = drupal_render_children($vars['form']);
  • Now create a directory inside your theme's directory called "templates" (assuming it doesn't exist already)
  • Then create a php file inside that folder called: "user-login-block.tpl.php" Inside this file, put the following code:
<div id="user-login-block-container">
  <div id="user-login-block-form-fields">
    <?php print $name; // Display username field ?>
    <?php print $pass; // Display Password field ?>
    <?php print $submit; // Display submit button ?>
    <?php print $rendered; // Display hidden elements (required for successful login) ?> 
  <div class="links">
    <a href="/user/register">Create an Account</a> | <a href="/user/password">Forgot Password</a>
  • CRITICAL STEP as an admin on your website, navigate to "admin/config/development/performance" and click "clear all caches" -- if you don't, then these changes won't display on your website
  • Modify the html markup inside "user-login-block.tpl.php" to your heart's content, and don't forget that you can also add those css classes to your main style.css file (AFAIK)
  • Hi Pravin, the method you showed me, it worked, but I didn't find document like this in drupal.org. Is it official way? And what's different between two methods: 1. Yours 2. Use block--[module]--[delta].tpl.php ? When each should be used? Thanks for your help.
    – Diradido
    Nov 21, 2014 at 7:43

Your Answer

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

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