here is a good one that has always stumped me.
I would love to see a solution in both D6 and D7.
I create custom modules and usually work with the menu api to create menu type -> MENU_CALLBACK.
Here is an example:
function example_menu() {
$items['example/page1'] = array(
'page callback' => 'example_page1_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
I would like to see the exact code solution to provide three different variables to be printed in a custom theme template based on the following code. To add to that challenge, I would like the code to be written in the menu callback function only. I know there are many possible ways to do it but could never figure out how to do it in a menu callback function which would be the most useful way.
//****************************************
// This code block goes in a custom module called example_menu_variables.module
// hook_menu example
function example_menu() {
$items['example/page1'] = array(
'page callback' => 'example_page1_callback',
'access callback' => TRUE,
'type' => MENU_CALLBACK,
);
return $items;
}
// hook_meny callback function
function example_page1_callback() {
// please provide code within this function to turn these next three
// variables into separate output variables for the template.
$variable_to_print1 = 'Foo';
$variable_to_print2 = 'Bar';
$variable_to_print3 = array('bing', 'bang', 'bong');
return;
}
//****************************************
//****************************************
// This block of code represents the part of the custom theme template related to the menu location from the hook_menu call
// D6 template name would be page-example-page1.tpl.php
// D7 template name would be page--example--page1.tpl.php
<div><?php print $variable_to_print1?></div>
<div><?php print $variable_to_print2?></div>
<div><?php print $variable_to_print3[0] . ' ' . $variable_to_print3[1] . ' ' . $variable_to_print3[2]?></div>
/*
output should look like:
Foo
Bar
bing bang bong
*/
//****************************************
Hope this is the kind of problem that someone wouldn't mind solving. Thanks for your time. :)
Ray James
hook_theme()
. Why does the code need to be contained within the menu callback function?