I want some of my pages to pull content from another application. Someone suggest I should write a module to do that. As I'm a complete beginner in Drupal I was wondering which hook do I need to implement (a snippet would be greatly appreciated) :

  • hook_page_alter
  • hook_page_delivery_callback_alter
  • something else ?
  • do you just want to add the content to your page or save it as a node in drupal? Commented Jan 21, 2013 at 8:03

1 Answer 1


hook_page_alter() is used to alter the page returned from another module, and hook_page_delivery_callback_alter() is used to change the page delivery callback for a page output from another module. All the hooks with a name ending with _alter are hooks that alter the output of another module, what another module returns, or the data stored by another module.

The hook you should use is hook_menu() to define a page callback, and drupal_http_request() to get the external content.
The minimal code you should use is similar to the following one.

  function mymodule_menu() {
    $items['abc/def'] = array(
      'page callback' => 'mymodule_external_content_view',
      'access arguments' => array('access content'),

    return $items;

function mymodule_external_content_view() {
  $response = drupal_http_request($url);
  if (!isset($response->error)) {
    $data = $response->data;

    return array(
      '#markup' => filter_xss($response->data, $allowed_tags)

Replace abc/def with the path of the page you want to output, $url with the URL of the external application, and $allowed_tags with an array of strings for the tags that you want to allow as output. By default, filter_xss() uses array('a', 'em', 'strong', 'cite', 'code', 'ul', 'ol', 'li', 'dl', 'dt', 'dd').

  • Do I need to have the abc/def page ? I would prefer to have only a menu entry as the page will be empty. Commented Jan 21, 2013 at 11:08
  • The path can be the one you prefer, not necessarily one containing a slash.
    – apaderno
    Commented Jan 21, 2013 at 12:27
  • Here is what I've done so far and which work (expect some bad URLs) : pastebin.com/UZhkMpjr Commented Jan 22, 2013 at 14:01

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.