1

In Drupal 7, I'm creating thank you page for a custom form and have following in my mymodule.module:

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

  $items['mymodule/thank_you/%'] = array(
    'title' => 'My Module Thank You Page',
    'description' => 'my module thank you page',
    'page callback' => 'mymodule_thank_you_page',
    'access arguments' => array( 'access mymodule thank you page' ),
    'type' => MENU_NORMAL_ITEM,
  );

  return $items;
}

function mymodule_theme() {
  return array(
    'mymodule_thank_you' => array(
      'variables' => array(
          'form_id' => NULL,
          'content' => NULL,
          'title' => NULL,
      ),
      'template' => 'thank-you',
      'file' => 'mymodule.theme.inc',
      'path' => drupal_get_path('module', 'mymodule') . '/templates',
    ),
  );
}

function mymodule_thank_you_page() {
  drupal_set_title( t( 'Thank You.' ) );

  $variables = array();

  return theme( 'mymodule_thank_you', $variables );
}

In mymodule.theme.inc, I have:

function template_preprocess_mymodule_thank_you( &$variables ) {
  $variables['title'] = 'test';
}

The problem I'm facing is that while I can access the thank-you template correctly, it doesn't read any of the variables I define in the preprocess function in the theme.inc file. Can anyone advice what I'm doing wrong for this?

0

I tried your thing on my local server. And its working fine. Just try in your template:

<?php
  // Print your defined variable here like this.
  print $title;
?>
1
  • Wierd. For me, it doesn't work as it tries to look for mymodule.theme.inc file in the templates folder instead of looking for it in main folder. For now, I've added the mymodule.theme.inc functions in mymodule.module and it seems to be working but there must be a cleaner solution to put everything in theme.inc file and still keep it in module's root folder instead of putting it in templates folder. – Drupal Themer Jun 13 '16 at 11:18

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.