bueller.ca

the digital workshop of Matt Ferris

Hotwire

Language(s)
PHP
Requirements
PHP 4

Includes

The files includes/header.<ext> and includes/footer.<ext> are included before and after the content of the requested template if they exist.

Plugins

Plugins parse templates, based of file extension. If a request is made for example.com/foo and the file pages/foo.html exists, Hotwire checks for a plugin that's registered for the html extension. Hotwire then calls on the plugin to parse the template and return the result, which it then assembles into a response and sends back to the client.

Plugins should be stored in the plugins directory and should be contained with their own directory. The only required file a plugin must have is plugin.php.

plugins/
    fooPlugin/
        plugin.php

On startup, Hotwire scans the plugins directory. Each directory under plugins that contains a plugin.php is considered a plugin and plugin.php is included. The plugin's directory name is used to determine the plugin's function namespace. For the example above, fooPlugin is assumed to have all functions prefixed with fooPlugin_*. Hotwire calls fooPlugin_register() to allow plugins to register the extensions they handle. fooPlugin_render('file') is called when processing template files, and expects a string to be returned.

<?php
// fooPlugin/plugin.php

/*
 * Register the 'foo' extension
 */
function fooPlugin_register ()
{
    return array('foo');
}

/*
 * Render template
 */
function fooPlugin_render ( $file )
{
    return file_get_contents($file);
}

File extensions

Includes and pages have extensions based on the plugin used to render them. It's possible to have a situation where two files exist for the same request with two different extensions. Hotwire will give priority to the plugin that was loaded the earliest. Priority can be set manually via the $extensionPriority array in config.php.

$extensionPriority = array('html', 'txt', 'php');

Comments