3

I have a Drupal's default User Login block in Side bar first region at the last position. Reference page: http://indiansnakes.org/snakes

The proposed home page has been redesigned and the User Login block has to be displayed in the Footer Fourth region. Reference Page: http://indiansnakes.org/homepage

So, the User Login block should appear in footer fourth only for this new homepage but for the rest of the pages in websites it has to continue to stay in the Side bar first region. In normal scenarios if it was a custom block, then I can create a clone of the same block and change the visibility per page / set of pages. But User Login block is system defined and it does not allow me to clone or duplicate it.

I tried searching if someone has already addressed this issue but it seems like not. Looking forward for thoughts.

Edit: Nearest I could find is this: Change block location on page by page basis?. But the solution there was to create multiple blocks from same view, unfortunately User Login is not based out of views for me.

2 Answers 2

4

You can place the default User Login block in Sidebar first region at the last position. You can exclude this block from being shown in Homepage using 'Visibility settings' which is available in the block edit page.

enter image description here

Then you can use front page template page--front.tpl.php and render the block manually by passing the block markup through hook_preprocess_page().

function THEME_NAME_preprocess_page(&$vars, $hook) {
  $front_page = drupal_is_front_page();
  if ($front_page) {
    $user_login= block_load('user', 'login');
    $vars['user_login'] = _block_get_renderable_array(_block_render_blocks(array($user_login)));
  }
}

Then you should print the $user_login variable in the front page template inside the Footer Fourth region.

1
  • Awesome answer! Will try this in the evening and accept it if it works for me. Thank you! Commented Jan 19, 2016 at 7:34
2

the context module does this (and more): https://www.drupal.org/project/context

it lets you make a context based on page (so front), then you tell it to display a block where you want it.

you can then make a second context based on page (not front) and display it in the other region.

this lets you reuse the block and avoids writing custom php in your template file.

1
  • Interesting, thanks for bringing it out. I will explore it. Commented Jan 19, 2016 at 11:35

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.