0
votes

I am a Drupal newbie. I am using Drupal 7.26 and I cannot create a new page using a custom module.

I made a new module called my_page by creating my_page.info and my_page.module files inside the module's own directory, but I am confused about which hooks to implement. I just want to return plain static html in that page.

I know I can make a page using admin panel but I want to do this programatically.

This is my .module code.

function my_page_simple() {
  return array('#markup' => '<p>' . t('Simple page: The quick brown fox jumps over the     lazy dog.') . '</p>');
}

When I navigate to /my_page I get 'Page not found'

1
have u declared the hook_menu mate..??Outlooker

1 Answers

1
votes

First declare a hook_menu function inside the my_page.module file.Since your module name is my_page your hook_menu will be named as my_page_menu. Hook_menu enables modules to register paths in order to define how URL requests are handled. Paths may be registered for URL handling only, or they can register a link to be placed in a menu.

function my_page_menu() {
  $items = array();
  $items['my_page'] = array(
    'title' => 'My Page',
    'description' => 'Study Hard',
    'page callback' => 'my_page_simple', //Calls the function
    'access arguments' => array('access content'),
  );
  return $items;
}   

function my_page_simple() {                                                                                                                                                                                                             
  return array('#markup' => '<p>' . t('Simple page: The quick brown fox jumps over the lazy dog.') . '</p>');
}

After adding this try clearing the drupal cache and then navigate to /my_page.Try reading more about the hook_menu here.Hope this helps u mate.. :)