2

I am working on a module where i have a page that must have no regions or extra content. A kind of "please wait" page.
How do i diable all extra content (regions menus...etc) ? i think Panels has this ability but i can't find the snippet it uses.
On another hand is it possible for a module to specify a special custom page ? like the maintenance-page for example ?

redben
  • 5,578
  • 5
  • 47
  • 63

4 Answers4

10

The page.tpl.php method is not flexible. It is based on a presentation logic. You should use hook_page_alter() for a business logic solution. For example:

function yourmodulename_page_alter(&$page) {
  if (current_path() == 'node/add/yourcontenttype') {
    unset($page['sidebar_first']);
  }
}

Also look at very powefull Context module.

user1984707
  • 101
  • 1
  • 3
  • This worked for me, but is this considered the best way? It seems like having a custom theme that doesn't use the sidebars would be better, but I couldn't get that to work. – cmcnulty Nov 07 '13 at 18:45
  • Generally this seems like a good way, but i noticed that even in this hook the blocks are already rendered. So the time to render the blocks is wasted! – donquixote Dec 17 '13 at 16:28
  • I like this solution a lot. I used it for removing regions on the 404 page by checking the request status. Since the 404 page URL can be anything there didn't seem to be a way to filter it in Drupal's block settings – Brett Gregson Jun 28 '17 at 12:56
1

If you want to do this before the blocks are rendered:

/**
 * Implements hook_block_list_alter()
 *
 * Hides the right sidebar on some pages.
 */
function THEME_NAME_block_list_alter(&$blocks) {

  // This condition could be more interesting.
  if (current_path() !== 'node/add/yourcontenttype') {
    return;
  }

  // Go through all blocks, and hide those in the 'sidebar_second' region.
  foreach ($blocks as $i => $block) {
    if ('sidebar_second' === $block->region) {
      // Hide this block.
      unset($blocks[$i]);
    }
  }
}

Note: Interestingly, this hook seems to work no matter if you have it in your theme or in a module. (Please correct me if I'm wrong)

donquixote
  • 4,877
  • 3
  • 31
  • 54
1

Only thing i can think of is writing checks in your page.tpl.php file to see if you on that "page" your talking about and not printing out the regions/menus, or use a different template. http://drupal.org/node/223440

Thor
  • 74
  • 1
  • 6
1

You can create a an extra page.tpl.php specifically for the page where you want to hide the regions. The naming principle is similar to the one for nodes.

Let's say you have a page with the url example.com/content/contact. A template named page--content--contact.tpl.php would serve that page and any page that starts with that url, i.e. the page example.com/content/contact/staff would also use that template (I think).

Check the classes of the body element for clues to what you can name your template, most themes will print that. In my example above, the body element would include the class page-content-contact.

angelika
  • 178
  • 4
  • So it means that with this method i cannot enforce it in my module, but when making the theme, right ? – redben Apr 16 '11 at 10:44
  • Well, you could probably just put the tpl-file in your module folder instead of your theme folder, if you want to keep it separate. But one could argue that the look and feel of that page is more to do with the theme than the module itself. It's more of a philosophical question, really ;) – angelika Apr 19 '11 at 11:49