Saturday 19 May 2012

Drupal: Create "hello world" module in drupal 7

This tutorial will show you the easiest way to create a module for drupal 7.

Begin:
  1. Go to 'modules' of drupal 7.
  2. Create 'hello_world' folder.
  3. Create two blank files: hello_world.info and hello_world.module under 'hello_world' under 'hello_world' folder.
  4. Open 'hello_world.info' and enter this content:
    name = Hello World
    description = This is my first module
    core = 7.x
  5. Go to 'Modules' at back-end, You will see your module listed here. Don't enable this module, because we still not finish yet.
  6. Create a menu link to call a page where will show 'hello world'. Open 'hello_world.module' and enter this content:
    function hello_world_menu() {

    $items['hello-world'] = array(


    'title' => 'Hello World',


    'page callback' => 'hello_world',


    'access arguments' => array('access content'),


    );


    return $items;

    }

    function hello_world() {

    return "hello world";

    }
  7. Go to home page and the result will look like this:

No comments:

Post a Comment