Specify which theme to use when rendering a page with drupal_render_page() I'm looking to send out a node as an HTML email. I have the code working except for one part.

I'm using drupal_render_page() to render the page's content so it's ready for an HTML email. I thought I'd use a custom theme for this (to take advantage of Drupal's theming layer).

However, I can't seem to figure out how I would specify a specific theme to use. Every time I run it it runs the current theme.

I'm not sure if this make a difference or not, but I'm using the Batch API to generate/send the emails.

I've tried changing the $theme and $theme_key globals in the batch callback, however that didn't seem to change anything.

I've also tried something like this in hook_custom_theme():

if (arg(0) == 'batch' &amp;&amp; $_REQUEST['op'] == 'do') {
  return 'email';
}


However, this also doesn't seem to change anything and still renders the email using the "seven" theme.

I've also tried using hook_batch_alter(), however changing the theme changes it for the batch process, (I still want the batch to process in the seven theme, I just want the email to be rendered in a different theme).

Thanks!
I discovered that menu_get_custom_theme() only uses a custom theme if the menu does NOT have a "theme callback". In the case of the batch process, it does have a theme callback: _system_batch_theme().

To specify what theme to use when rendering a batch process, I had to use hook_menu_alter() to change the theme callback to my own.

function MYMODULE_menu_alter(&amp;$items) {

  $items['batch']['theme callback'] = 'MYMODULE_batch_theme';

}


Then I just needed to add a conditional

function MYMODULE_batch_theme() {

  // Use a Custom Theme
  if ($_REQUEST['op'] == 'do') {
    return 'email';
  }
  else {
    return _system_batch_theme();
  }

}


This fixes the problem by specify the custom theme in the theme callback rather than in hook_custom_theme() (which is ignored when a theme callback is present).

Thanks!