5

We can add a custom block with php code easily. Just enable php code and add a block. But what about a page? How can I add a page with custom php code?

0

1 Answer 1

11

Since you already know how to provide a block through a custom module here is what you need to add:

/**
 * Implements hook_menu().
 */
function modulename_menu() {

  $items['your/special/path'] = array(
    'type' => MENU_NORMAL_ITEM,
    'title' => t('Title'),
    'description' => 'My custom and very special page',
    'page callback' => 'modulename_special_page',
    'access callback' => 'user_access',
    'access arguments' => array('access content'),
  );

  return $items;
}

/**
 * Page callback.
 */
function modulename_special_page() {
  $content = 'Hello World';
  // ... do something and add to $content;
  return $content;
}

So first you need to register a path by implementing hook_menu and there you need to provide a page callback which itself returns the contents of your page.

Check out the example modules for further variations. There is one submodule that shows a lot of examples regarding registering new pages/tabs/etc.

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.