Experimental Project

This is a sandbox project, which contains experimental code for developer use only.

This project demonstrates how to create a simple page with a Drupal module quickly. It has the following 4 files:

1. simple_page_demo.info - Necessary information of the module.
2. simple_page_demo.module - PHP code.
3. simple_page_1.tpl.php - HTML template for demo page 1.
4. simple_page_2.tpl.php - HTML template for demo page 2.

Enable this module, and demo pages are avaialble at:
http://hostname/demo/simple_page_1
http://hostname/demo/simple_page_2

Basically it uses the hook_menu and hook_theme APIs, code logic can go into the simple_page_1_callback function, while the HTML tags can go into simple_page_1.tpl.php file.

simple_page_2 is especially a demo of page without theme.

Hopes it helps newbies like me in learning Drupal!

Here is the code in simple_page_demo.module:

<?php
/**
* @file
* Create simple pages within this module.
*/
/**
* Implements hook_theme().
*/
function simple_page_demo_theme() {
  return array(
    'simple_page_1' => array(
      'variables' => array(),
      'path' => drupal_get_path('module', 'simple_page_demo'),
      'template' => 'simple_page_1',
    ),
    'simple_page_2' => array(
      'variables' => array(),
      'path' => drupal_get_path('module', 'simple_page_demo'),
      'template' => 'simple_page_2',
    ),
  );
}
/**
* Implements hook_menu().
*/
function simple_page_demo_menu() {
  $items['demo/simple_page_1'] = array(
    'title' => 'Simple Page 1',
    'page callback' => 'simple_page_1_callback',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  $items['demo/simple_page_2'] = array(
    'title' => 'Simple Page 2',
    'page callback' => 'simple_page_2_callback',
    'access arguments' => array('access content'),
    'type' => MENU_CALLBACK,
  );
  return $items;
}
function simple_page_1_callback() {
  return theme('simple_page_1', array());
}
function simple_page_2_callback() {
  print theme('simple_page_2', array());
}

Project Information