For example: I want to change default login block template.

My current template file is — /sites/all/themes/{theme_name}/templates/block--user--login.tpl.php

But I want — /sites/all/themes/{theme_name}/templates/system_blocks/login-block.tpl.php

How can I do that?

1 Answer 1


Check out template_preprocess_block. You can do this with the following code in your theme's template.php file:

function MYTHEME_preprocess_block(&$variables) {
  // Perform a check based on any parameter, e.g. block ID.
  if ($variables['block_html_id'] == 'block-system-main') {
    // This will lookup for block--system-main-block.tpl.php file in your
    // theme.
    $variables['theme_hook_suggestions'] = 'block__system_main_block';

However, Drupal already looks for various template names, before it settles down for the default block.tpl.php. Here is the list:

  1. block--block--[block-id].tpl.php
  2. block--[module]--[delta].tpl.php
  3. block--[module].tpl.php
  4. block--[region].tpl.php
  5. block.tpl.php

See this page for more information.

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.