Skip to content

Instantly share code, notes, and snippets.

@josedigital
Forked from somatonic/ModuleName.module
Created July 25, 2012 18:05
Show Gist options
  • Select an option

  • Save josedigital/3177586 to your computer and use it in GitHub Desktop.

Select an option

Save josedigital/3177586 to your computer and use it in GitHub Desktop.

Revisions

  1. @somatonic somatonic created this gist May 19, 2012.
    58 changes: 58 additions & 0 deletions ModuleName.module
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,58 @@
    <?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);
    }


    }