1

I've put together my first Drupal 7 custom module. I've implemented hook_menu() to get it to path correctly, but I cannot seem to get the output wrapped in the page tpl.

I can visit domain.com/mycustommodule to see the output, but it's just the photos and links that the custom module built, not the site wrapper. How do I get this output into the node area of the page?

Here's my hook_menu if that helps.

function mymodule_menu() {

$items = array(); 
$items['mymodule/view'] = array(
'title' => 'Mymodule',
'page callback' => 'mymodule_display',
'access callback' => 'user_access',
'access arguments' => array('Access administration menu'),
'weight' => 1,
'type' => MENU_CALLBACK,
);
return $items;
}
3

What would help is the code for the mymodule_display() function. However, it sounds like you are printing the output in the function instead of returning it.

Blank page:

/**
 * Creates a blank page with only the module output.
 */
function mymodule_display() {
  print 'Module content';
}

Themed page:

/**
 * Output the content in the main content area of active theme.
 */
function mymodule_display() {
  return 'Module content';
}
  • That makes sense. I'm printing out the location of images on the local file system, as the location changes by the date. There's not much to that function, other than a for loop going back fourteen days and returning the images for those days. Thanks for your help, enzipher! – jscrilla May 16 '13 at 2:51
0

You should go to domain.com/mymodule/view to see the output of your mymodule_display function.

The complete code will be

function mymodule_menu() {
 $items = array(); 
 $items['mymodule/view'] = array(
 'title' => 'Mymodule',
 'page callback' => 'mymodule_display',
 'access callback' => 'user_access',
 'access arguments' => array('access content'),
 'weight' => 1,
 'type' => MENU_CALLBACK,
 );
 return $items;
}


function mymodule_display() {
 return '<h2>Heres is your module's output</h2>';
}

Make sure you clear cache after writing this code.

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.