0

I want to pass the value from module to page tpl file in drupal.I have created a custom module 'one_time_popup'.I have created a sample soutput and tried to pass it and print in page.tpl.php after footer section.but doesn't shows any thing.What I did wrong.I'm a newbie

function one_time_popup_menu(){
$items['oneTimePopupData'] = array(
'title' => 'One time Popup',
'page callback' => 'one_time_popup_user_login',
'type' => MENU_CALLBACK,
'access callback' => TRUE,
);
return $items;
}
function one_time_popup_user_login(&$edit, $account){
 ...
$output='value from one time popup module!';
return theme('photo_order',array('results' => $output));
} 
function one_time_popup_theme() {
 return array(
'photo_order' => array(
  'template' => 'page',
  'variables' => array(
    'results' => NULL,
  ),
 ),
 ); 
}

Tpl file(page.tpl)
<?php echo $results; ?>

1 Answer 1

0
<?php
/**
 * Implements hook_menu()
 */
function mymodule_menu() {
  $items = array(
      'custom_menu_item' => array(
        'title' => 'Hello world',
        'page callback' => '_page_hello_world',
        'access callback' => TRUE,
      ),
    );
  return $items;
}

/**
 * Implements hook_theme().
 */
function mymodule_theme() {
  $theme = array();
  $theme['mymodule_template'] = array(
    'template' => 'mymodule-template',
  );
  return $theme;
}

/**
 * Preprocessor function for 'mymodule_template'.
 */
function template_preprocess_mymodule_template(&$vars) {
  $vars['hello'] = 'hello!';
}

/**
 * Page callback.
 */
function _page_hello_world() {
  return theme('mymodule_template');

}

A $hello variable is available in your template at path /custom_menu_item

1
  • can you explain this Commented Sep 4, 2017 at 8:34

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.