How to show only block and hide all other menus,blocks etc., This is my code

function example_menu() {
  $items['appointcal'] = array(
    'page callback' => 'example_show',
    'access callback' => TRUE,
     'type' => MENU_CALLBACK,
     return $items;

function example_show() {
  return theme('example_cal');

function example_theme() {
  return array(
    'example_cal' => array(
      'render element' => 'elements',
      'template' => 'templates/examplecal'

My examplecal.tpl.php is

    $block = module_invoke('views', 'block_view', 'example-block');
    print render($block['content']);

enter image description here

There is need to show only region that is in red color and hide all other regions.

  • my example.tpl.php code is <div> <?php $block = module_invoke('views', 'block_view', 'appointment_calendar-block'); print render($block['content']); ?> </div>
    – Ajay Reddy
    Jul 24, 2015 at 9:41
  • Change tpl file name to "page--examplecal.tpl.php" and try.
    – Abin
    Jul 24, 2015 at 9:54

3 Answers 3


Create a Custom tpl for your page by editing page.tpl.php. Name should be page--yourmenuname.tpl.php. In that page tpl remove all unwanted contents/regions and render your block in required region using [block_load($module, $delta)]1;

$block = block_load('name','delta');
$output = _block_get_renderable_array(_block_render_blocks(array($block)));
print render($output);

Hope this will help you..

  • Can i include page--yourmenuname.tpl.php in mymodule folder. Will this work?
    – Ajay Reddy
    Jul 24, 2015 at 9:52
  • 1
    Put page--yourmenuname.tpl.php in you /template folder of your active theme.
    – Abin
    Jul 24, 2015 at 9:56
  • did you changed yourmenuname ..?? Change to appointcal in your case
    – Abin
    Jul 24, 2015 at 9:59
  • This answer is correct @AAjayKumarReddy You just need to name your template page--appointcal.tpl.php because your menu path is /appointcal
    – Beebee
    Jul 24, 2015 at 10:05
  • 1
    Just saying, this will unnecessarily process all the blocks, only to hide them later. So it is not the best in performance.
    – donquixote
    Jul 24, 2015 at 11:05

You can use Context module for this purpose. It provides the same functionality as you require.

Note: If you don't want to use any extra module, then it can also be done simply through block configuration setting. There are three options to control the block visibility.

  • I want to do it programatically , need not to use other modules
    – Ajay Reddy
    Jul 24, 2015 at 9:42
  • Then you're doing it wrong, the Context module is designed for tasks like this. The context module is used by over 188,000 sites and is rigorously tested, doing it programatically introduces scope for error. Jul 24, 2015 at 9:56
  • Why are you going towards complexity? If you don't want to use any extra module then it can also be done simply through block configuration setting. There are three options to control the block visibility. Try this.
    – WaQaR Ali
    Jul 24, 2015 at 9:59

There are two things, depending on your requirements. (People finding this question may have different ideas what they want)

Programmatically controlling which blocks appear on a page.

Create a custom module with hook_block_list_alter(). There you remove all those blocks that you don't want, depending on the current page.

The advantage of this is that you prevent these blocks from being rendered and processed.

Showing a page without blocks / "decorations".

If you want a page with only the main content, and no sidebars, blocks and stuff, you can create a page callback which prints the page html directly, and then calls drupal_exit().

You still want to deliver a complete html page, so you need to make sure that your page callback does something like theme('html', ..). This is "homework" for you to figure out :)

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.