I've been asking in IRC, but nobody has ansered...

In D6, is it possible for my module to specify a different page.tpl.php template to be used by the template engine?

Comments

nevets’s picture

It should work since the module can implement hook_preprocess_page and make template suggestions. Template may need to be in theme folder though.

jtsnow’s picture

Thanks!

This works great. I am able to it add template suggestions via $variables['template_files']. However, following a form submission, my template suggestions do not exist. Any reason for this?

nevets’s picture

What does your hook_preprocess_page look like?

jtsnow’s picture

Ok, this is essentially what I am trying to do:
The problem is that neither my global $widgets_mode or $_POST are available in hook_preprocess_page after a form submission. This is strange because they are definitely there in hook_init. Any suggestions?

function embed_widgets_init() {
  global $widgets_mode;
  
  if ($_POST['widgets_mode']) {
    drupal_set_message("POST widgets mode = true");
    // This is displayed after a form submission!
  }

  if ($_REQUEST['widgets_mode'] || $_POST['widgets_mode']) {
    $widgets_mode = TRUE;
  }
  else {
    $widgets_mode = FALSE;
  }
}
function embed_widgets_form_alter(&$form, $form_state, $form_id) {
  global $widgets_mode;
  if ($widgets_mode) {
    $form['widgets_mode'] = array(
      '#type' => 'hidden',
      '#value' => TRUE,
    );
  }
}
function embed_widgets_preprocess_page(&$variables) {
  global $widgets_mode;
  print "<pre>" .  Print_r($_POST, true) . "</pre>"; // At this point, $_POST is empty after a form submission.
  print "<pre>" .  Print_r($widgets_mode, true) . "</pre>";
  
  if ($widgets_mode || $_POST['widgets_mode']) {
    // make my changes to $variables['template_files'] here.
  }
}
nevets’s picture

Is this node related? From your original question is sounded like this is related to adding node content of a particular type.

Because of the way form submission and the redirect works, $widgets_mode will never be true after the redirect. If this node related you probably want something like

function embed_widgets_preprocess_page(&$variables) {
   if ( isset($variables['node']) ) {
      $node = $variables['node']);
      if ( $node->type ==  'your_content_type' ) {
         // make my changes to $variables['template_files'] here.
      }
   }
}

If not about node content then what is the page trying to display?

jtsnow’s picture

No, this is not node related. My module generates "widget" versions of pages. (See http://drupal.org/project/embed_widgets)

It current does not work with web forms. The goal is to allow a user to submit a form and still get a widget-friendly response from the form. So, I need a way to override page.tpl.php after a form submission.

jtsnow’s picture

Problem solved. I am able to check $_SERVER['HTTP_REFERER'] to see if the referring URL contains widgets_mode=true.