This might be a daft question (that's why I'm here; if I understood things I would not ask the question), but how do I download the page_example module:
http://api.drupal.org/api/drupal/developer--examples--page_example--page...

I'm used to downloading modules as follows:

  1. Go to http://drupal.org/project/Modules and find the module I want
  2. Click on the "download" button!

but I've looked there for a module called "page_example" but it isn't there.

Isn't it possible to download the example module? Or do I somehow have to download each file from the above http://api.drupal.org link?

It's all a bit fishy to me!! I'm sure this must seem a really dumb question to those of you who know the answer.

If the answer is, "No, you can't download the page_example" module as if it were a normal module, er, why not?!?

Thanks!

Comments

maxferrario’s picture

In the page_example module page click on the "View source" link you find under the title and the Drupal version.
The body of the page will then show you the PHP code of the module: copy it (from

<?php
// $Id: page_example.module,v 1.1.2.6 2010/09/03 17:08:33 rfay Exp $

to

return theme('item_list', $list);
}

)
and create the page_example.module file with a standard text editor.

Hope this helps

drupalshrek’s picture

OK, thanks. It seems to me a pity that for the example module I need a different way to load it and try it than the other modules, but hey.

drupalshrek

jaypan’s picture

The other modules are actual modules to be used on a site. The module you are looking at is just an example of how to write a module.

Contact me to contract me for D7 -> D10/11 migrations.

drupalshrek’s picture

Even so, it had me as a novice baffled for a while, to the point I had to post a forum question.

If the example were actually available as a real downloadable module it would make it easier for people learning to try it out and test and learn.

drupalshrek

sunwin’s picture

<?php
function page_example_arguments($first, $second) {
  // Make sure you don't trust the URL to be safe! Always check for exploits.
  if (!is_numeric($first) || !is_numeric($second)) {
    // We will just show a standard "access denied" page in this case.
    drupal_access_denied();
    return;  // We actually don't get here.
  }

  $list[] = t("First number was @number.", array('@number' => $first));
  $list[] = t("Second number was @number.", array('@number' => $second));
  $list[] = t('The total was @number.', array('@number' => $first + $second));

  return theme('item_list', $list);
}

function page_example_description() {
  return '<p>'.t('The page_example provides two pages, "simple" and "arguments". The <a href="@simple_link">simple page</a> just returns a string for display. The <a href="@arguments_link">arguments page</a> takes two arguments and displays them, as in @arguments_link', array('@simple_link' => url('examples/page_example/simple', array('absolute' => TRUE)), '@arguments_link' => url('examples/page_example/arguments/23/56', array('absolute' => TRUE)))).'<p>';
}

function page_example_help($path, $arg) {
  switch ($path) {
    case 'examples/help#simple':
      // Here is some help text for a custom page. This information will be
      // introduced in the page when viewing example/foo URL.
      return t('This sentence contains all the letters in the English alphabet.');
  }
}

function page_example_menu() {
  // This is the minimum information you can provide for a menu item. This menu
  // item will be created in the default menu.
  $items['examples/page_example'] = array(
    'title' => 'Page Example',
    'page callback' => 'page_example_description',
    'access callback' => TRUE,
    'expanded' => TRUE,
  );

  $items['examples/page_example/simple'] = array(
    'title' => 'Simple - no arguments',
    'page callback' => 'page_example_simple',
    'access arguments' => array('access simple page'),
  );

  // By using the MENU_CALLBACK type, we can register the callback for this
  // path but do not have the item show up in the menu; the admin is not allowed
  // to enable the item in the menu, either.
  //
  // Notice that the 'page arguments' is an array of numbers. These will be
  // replaced with the corresponding parts of the menu path. In this case a 0
  // would be replaced by 'example', a 1 by 'baz', and like wise 2 and 3 will
  // be replaced by what ever the user provides. These will be passed as
  // arguments to the page_example_baz() function.
  $items['examples/page_example/arguments/%/%'] = array(
    'title' => 'Page example with arguments',
    'page callback' => 'page_example_arguments',
    'page arguments' => array(3, 4),
    'access arguments' => array('access arguments page'),
    'type' => MENU_CALLBACK,
  );

  return $items;
}

function page_example_perm() {
  return array(
    'access simple page',
    'access arguments page',
  );
}

function page_example_simple() {
  return '<p>' . t('Simple page: The quick brown fox jumps over the lazy dog.') . '</p>';
}
?>
dergachev’s picture

Page Example module is actually contained in the Examples for Developers project. See http://drupal.org/project/examples
So to install and enable it with drush, just do the following: (untested)

drush dl examples
drush -y en page_example

Hope that helps!