Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ProcessWire Module Template
<?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
You can’t perform that action at this time.