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?

1 Answer 1


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

  // Print your defined variable here like this.
  print $title;
  • 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. Jun 13, 2016 at 11:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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