0

I'm building a custom module that denies access to the site based on some custom rule.

I;ve already build the module form, variables get stored, in hook_init I do my check against the variables I set on my custom module.

What I would like to do now is to have a template behaviour like the maintenance mode one.

By default it should be a blank page with Site name and message like maintenance mode(maybe overriding html.tpl.php). The default mymodule-page.tpl.php should leave in mymodule/templates/

This page can be overridden in theme folder so the user can apply its own style, logo, region etc...

function my_custom_module_menu{
  $items['my-custom-module-page'] = array(
    'title' => t('My custom module  title'),
    'page callback' => 'my_custom_module_page_callback',
    'type' => MENU_CALLBACK,
  );
}

function my_custom_module_theme($existing, $type, $theme, $path) {
  return array(
    'my_custom_module_template' => array(
      'template' => 'my-custom-module-template',
      'variables' => array('variable' => NULL),
    ),
  );
}

function my_custom_module_page_callback() {
  return theme('my_custom_module_template');
}

The code above keeps the layout of the page but I would like to override the entire page.

Which hooks should I use to achieve this? How can I call this template from my hook_init?

Thanks in advance.

  • Would you care to share any code? You can just do a page callback as well. – kyletaylored Nov 8 '14 at 15:11
  • Since the array key is referring to the theme function as my_custom_module_template, the template filename cannot be my-custom-module; it should be my-custom-module-template. – kiamlaluno Nov 8 '14 at 17:37
  • Is it a rule to keep consistency? It's working but the page still prints regions. btw I changed following your suggestion and it's still printing regions. – Tyler Durden Nov 8 '14 at 17:48
  • That is for another reason. :) I will write an answer ASAP. – kiamlaluno Nov 8 '14 at 18:06
  • Thanks :D I'm keeping your suggestions for more consistency. – Tyler Durden Nov 8 '14 at 18:24
1

You are getting the regions being printed because your page callback is returning a string. If you want your page callback to just print your output, you need to change your code to the following one.

function my_custom_module_page_callback() {
  print theme('my_custom_module_template');
}

The reason is visible in drupal_deliver_html_page(), which uses the following code.

// Menu status constants are integers; page content is a string or array. if (is_int($page_callback_result)) { // Omissis } elseif (isset($page_callback_result)) { // Print anything besides a menu constant, assuming it's not NULL or // undefined. print drupal_render_page($page_callback_result); }

If your page callback returns NULL (which also happens when it doesn't have an explicit return statement), then drupal_render_page() will not be called. As result, just the output from your page callback will be returned to the browser.

This is what node_feed() does: It prints an RSS feed without letting Drupal output anything else. Contrary, the output would not be handled as a RSS feed from the client side.

  • Thanks, good explanation. I've moved my custom tpl.php file into my theme and it get called. How can I give the user to print theme component like logo menu region etc..? – Tyler Durden Nov 9 '14 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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