About Hello World

An example module used for demonstration purposes.

Category Proof of Concept
Proof of concept modules are designed as examples or starting points for others to build from. May not be ideal for users wanting to plug-n-play.
Release StateStable
Should be safe for use in production environments. *
Authorryan
Module Version0.0.2
Class NameHelloworld
Compatibility2.3, 2.4, 2.5, 2.6, 2.7, 3.0
Date AddedSeptember 22, 2014
Recommended ByNew recommendations may take up to 1 day to appear.

Instructions

This module's files should be placed in /site/modules/Helloworld/
How to install or uninstall modules

README

ProcessWire 'Hello world' demonstration module

Demonstrates the Module interface and how to add hooks.This version of Helloworld requires ProcessWire 2.6.0 or newer. This can also serve as a starting point for building your own modules.

What this module does

Everything that this module does is purely for demonstration purposes.It doesn't do anything particularly useful, but reveals a lot about what you can do with modules and hooks. Here's what it does:

  • Adds a hook after Page::render to output a hello world message at thebottom of editable pages (if enabled in the module configuration). Just to make it somewhat useful, clicking it takes you to the editor for that page.

  • Adds a hook after Pages::save to display a hello notification everytime you save a page.

  • Adds a $page->hello() method to all pages, which simply returns yourhello world message and information about the page. Optionally provide an argument with some text, i.e. $page->hello('some text') to have itincluded in the return value.

  • Adds a $page->hello_world property to all pages. Accessing it simplyreturns "Hello [your-user-name]".

  • Adds a ProcessPageEdit::execute hook, which displays a notification toyou only when you edit the homepage.

How to test this module

  1. Install the module from your admin (Modules > Site > Hello World).

  2. Configure the module.

  3. After testing it, look at the code and read the comments. At this point you maywant play with it and modify it to do something useful.

How to use this to make your own module

To see exactly what this module does, you may want to install it as-is first.Then uninstall and follow the instructions below.

  1. Rename the directory and all files, replacing "Helloworld" with the name of your module.

  2. Change the class name in the module file to be [YourModuleName]. This should be the samename that you used for your module file (minus the ".module.php" part).

  3. Modify the code of the module to do what you want. You can simply remove all of themethods in it, though you may wish to leave these method definitions in place: init() and/or ready(), ___install(), ___uninstall().

  4. Edit the [YourModuleName].info.php file to contain info specific to your module.

  5. If you want your module to be configurable, edit the [YourModuleName].config.phpfile, update the configuration as needed. If you do not need a configurable module, simply remove the file.

  6. Update this README.md file to contain information specific to your module.

  7. When you've got something you'd like to share, post your module to GitHub and tomodules.processwire.com!

Stop by the ProcessWire forums anytime and we will be gladto help with any questions.


ProcessWire Copyright 2015 by Ryan Cramer

Comments

No comments yet. Be the first to post!

Post a Comment

Your e-mail is kept confidential and not included with your comment. Website is optional.