Femto supports plugins to extend its functions.
- Add Trailing Slash - Redirect to the subfolder of the same name if a page doesn't exist.
- Directory - Display a list of page in a directory.
- Gallery - Gap-less image galleries.
- Image - Link to and display images from the content folder.
- Page Extra - Extra information and sorting option for pages.
- PDF - Render pages as PDF files.
- PHP - Add PHP code to your pages.
- PHP Legacy - Associate PHP scripts with your pages.
- Redirect - Redirect a page to somewhere else.
- TOC - Display a table of content.
Plugins are essentially a class in a php file of the same name. Class name is
case sensitive, file name will always be lower case. Plugins need to be in the
femto\plugin
namespace. This example plugin would go in my_plugin.php
:
namespace femto\plugin;
class My_Plugin {
//...
}
The plugin class can define functions with specific names -hooks- to be called when the corresponding event happens. Below is a list of available hooks, most parameters are passed by reference:
Let you initialise your plugin with the given configuration.
Called when the URL has been cleaned and is about to be dispatched.
Called if the request didn't match anything.
Called when the request has been completed, even if it did not match anything, before the page is inserted in the template.
Called before parsing a page's header. It is possible add custom headers at this point:
public function page_parse_header_before(&$headers) {
$headers['name'] = 'default value';
}
This hook is not called if the page is served from cache.
Called after parsing a page's header but before parsing its content. This hook is not called if the page is served from cache.
Called before parsing a page's content. This hook is not called if the page is
served from cache. Page content cache can be disabled with the no-cache
flag.
Called after parsing a page's content. This hook is not called if the page is
served from cache. Page content cache can be disabled with the no-cache
flag.
Called before rendering the page with the appropriate template. This hook is not
called if the no-theme
flag is set.
Called just before displaying the page with the final output.
Called when a directory listing is completed. This hook is not called if the directory's information is taken from the cache.
Called when a directory is being sorted. Note that directories should always be sorted in descending order, Femto will reverse it if needed.
Called when the plugin's url is accessed (e.g.
http://example.com/plugin/my_plugin/foo/bar
). Only the relevant part of the
url is passed as argument (e.g. foo/bar
).