logo
  Wiki
Advanced search
         




Hooks

Overview

Hooks is a mechanism that allows to extend the functionality without modifying existing code. Basically, plugins? use hooks to "inject" their own code into the flow of execution for a given operation (for example, displaying a topic page). To make this possible, the software executes calls to a hook function in various locations. If no plugin has subscribed to a given hook, nothing happens and the hook function will return immediately. If, however, a plugin has indicated the intention to use a hook, its code will be executed when the hook function is called.

Hooks are chainable which means that multiple plugins can execute code in the same hook. Each hook has a clearly identifiable and descriptive name, for example boardindex is a valid hook name. To use a hook, a plugin must do the following things:

  • Indicate the hook(s) it wants to use.
  • Provide a piece of code (usually a function) that shall execute when the hook is called.


Hooks are persistently stored in the database when a plugin is activated and deleted when a plugin is deactivated. A deactivated plugin will therefore never execute any code.

Code hooks versus template hooks

There are 2 fundamentally different types of hooks in EoS Alpha:

  1. Code hooks. They run in the so-called backend code (the code which does the main work, like fetching and preparing data from the database, dealing with all kind of user input, controlling access permissions and much more. The back-end does, however, not display anything. Code hooks are persistent and will always execute as long as there is at least one subscriber for a hook.
  2. Template hooks. A template hook is similar except that it is dynamic. A plugin that wants to output results from its own back-end work must use a template hook. A template hook is a piece of Smarty template code that will simply be inserted at the given hook location. For example, the header_area template hook will be inserted at the very top of the page (the header, where the logo resides). A plugin that wants to modify the header must therefore register a template fragment in the header_area hook.
Page generation time: 0.084 seconds