Skip to content

Instantly share code, notes, and snippets.

@kongondo
Forked from somatonic/ModuleName.module
Created June 7, 2013 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kongondo/5728103 to your computer and use it in GitHub Desktop.
Save kongondo/5728103 to your computer and use it in GitHub Desktop.
ProcessWire Module Template. It demonstrates the Module interface and how hooks are added
<?php
/**
* ProcessWire Module Template
*
* Demonstrates the Module interface and how to add hooks.
*
* ProcessWire 2.x
* Copyright (C) 2010 by Ryan Cramer
* Licensed under GNU/GPL v2, see LICENSE.TXT
*
* http://www.processwire.com
* http://www.ryancramer.com
*
*/
class ModuleName extends WireData implements Module {
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array
*
*/
public static function getModuleInfo() {
return array(
'title' => 'ModuleName',
'version' => 100,
'summary' => '',
'href' => '',
'singular' => true,
'autoload' => true
);
}
public function init() {
// add a hook after each page is rendered and modify the output
$this->addHookAfter('Page::render', $this, 'example2');
}
public function example2($event) {
$page = $event->object;
// don't add this to the admin pages
if($page->template == 'admin') return;
// add a "Hello World" paragraph right before the closing body tag
$event->return = str_replace("</body>", "<p>Hello World!</p></body>", $event->return);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment