Issue a html.tpl.php override from a module? Is there a way to override the output of a page from a contributed module and issue your own html.tpl.php, effectively taking control of the output from the theme?

I want to do this in effort to create a unique login/registration experience, but can only seem to override the page level template, not the html level template. I see that the print module kind of does this, but is that the way to approach it?
According to this answer, you could simply print the page content in the menu page callback rather than returning it.


  To get data from Drupal's database and/or produced in PHP, you need a
  page callback (in a custom module) that output the data without the
  full layout rendering. This is easily doable by printing the content
  of the page directly in your page callback instead of returning it.


I guess the Print module implemented the printer-friendly page in this way. The following is the code snippet from the module.

function print_menu() {
  $items = array();

  $items[PRINT_PATH] = array(
    'title' =&gt; 'Printer-friendly',
    'page callback' =&gt; 'print_controller_html',
    'access arguments' =&gt; array('access print'),
    'type' =&gt; MENU_CALLBACK,
    'file' =&gt; 'print.pages.inc',
  );
  ........   
}   

/**
 * Generate an HTML version of the printer-friendly page
 *
 * @see print_controller()
 */
function print_controller_html() {
  $args = func_get_args();
  $path = filter_xss(implode('/', $args));
  $cid = isset($_GET['comment']) ? (int)$_GET['comment'] : NULL;

  // Handle the query
  $query = $_GET;
  unset($query['q']);

  $print = print_controller($path, $query, $cid, PRINT_HTML_FORMAT);
  if ($print !== FALSE) {
    $node = $print['node'];
    $html = theme('print', array('print' =&gt; $print, 'type' =&gt; PRINT_HTML_FORMAT, 'node' =&gt; $node));
    drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
    drupal_send_headers();
    print $html;
    ......
}


According to this, the module uses the custom HTML template print.tpl.php. It is a HTML-level template. The module then gets the HTML by calling theme('print',...) and render it directly to the browser using print $html;.

Here is a general idea for your purpose: mymodule.module

/**
 * Implements hook_menu().
 */
function mymodule_menu() {
  $items = array();
  $items['mylogin'] = array(
    'title' =&gt; 'Custom Login Page',
    'page callback' =&gt; 'mymodule_custom_login_page',
    'type' =&gt; MENU_CALLBACK,
    'access callback' =&gt; TRUE,
  );

  return $items;
} 
/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  return array(
    'mylogin' =&gt; array(
      'variables' =&gt; array('page' =&gt; array()),
      'template' =&gt; 'mylogin', // mylogin.tpl.php in your module folder
    ),
  );
}
/**
 * Generate a custom login page
 * @see more in print_controller_html() in print.pages.inc of the Print module 
 */
function mymodule_custom_login_page(){
    $page = _mymodule_login_page_prerequisite(); // get/prepare necessary variables, js, css for the page
    $page['form'] = drupal_render(drupal_get_form('user_login')); // get login form
    // prepare html in mylogin.tpl.php
    // See more in print.tpl.php() in the Print module  
    $html = theme('mylogin', array('page' =&gt; $page)); 

    drupal_add_http_header('Content-Type', 'text/html; charset=utf-8');
    drupal_send_headers();
    print $html; // cease Drupal page rendering and render directly to the browser
} 
/**
 * Prepare the array for the template with common details
 * @see more _print_var_generator() in print.pages.inc of the Print module
 */
function _mymodule_login_page_prerequisite(){
    global $base_url, $language; 
    $page = array();
    $page['language']   = $language-&gt;language;
    $page['head']       = drupal_get_html_head();
    $page['title']      = '';
    $page['scripts']    = drupal_get_js();
    $page['favicon']    = '';
    // if there is a custom css file for this page
    // drupal_add_css(drupal_get_path('module', 'mymodule') . '/css/mylogin.css');
    $page['css'] = drupal_get_css();
    $page['message'] = drupal_get_messages();
    $page['footer_scripts'] = drupal_get_js('footer');

    return $page;
} 


Template: mylogin.tpl.php

&lt;?php
/**
 * @file
 * Custom login page template
 *
 * @ingroup page
 */
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml" lang="&lt;?php print $page['language']; ?&gt;" xml:lang="&lt;?php print $page['language']; ?&gt;"&gt;
  &lt;head&gt;
    &lt;?php print $page['head']; ?&gt;
    &lt;title&gt;&lt;?php print $page['title']; ?&gt;&lt;/title&gt;
    &lt;?php print $page['scripts']; ?&gt;
    &lt;?php print $page['favicon']; ?&gt;
    &lt;?php print $page['css']; ?&gt;
  &lt;/head&gt;
  &lt;body&gt;
    &lt;h3&gt;This is custom login page.&lt;/h3&gt;
    &lt;?php 
    if (!empty($page['message'])):
        foreach($page['message'] as $type =&gt; $message):
        ?&gt;
            &lt;div class="messages &lt;?php print $type; ?&gt;"&gt;
                &lt;ul&gt;
                &lt;?php foreach($message as $msg): ?&gt;
                    &lt;li&gt;&lt;?php print $msg; ?&gt;&lt;/li&gt;
                &lt;?php endforeach; ?&gt;
                &lt;/ul&gt;
            &lt;/div&gt;
        &lt;?php
        endforeach;
    endif; ?&gt;
    &lt;div&gt;&lt;?php print $page['form']; ?&gt;&lt;/div&gt;
    &lt;?php print $page['footer_scripts']; ?&gt;
  &lt;/body&gt;
&lt;/html&gt;


I hope this will customize your login page as you need.