Elgg offers a facility to manage your plugin pages via a page handler, enabling custom urls like
http://yoursite/your_plugin/section. To add a page handler to a plugin, a handler function needs to be registered in the plugin’s
start.php file with
The plugin’s page handler is passed two parameters:
- an array containing the sections of the URL exploded by ‚/‘. With this information the handler will be able to apply any logic necessary, for example loading the appropriate view and returning its contents.
- the handler, this is the handler that is currently used (in our example
your_plugin). If you don’t register multiple page handlers to the same function you’ll never need this.
Pages in plugins should be rendered via page handlers (not by using
Elgg\Application). Generally the rendering is done by views with names starting with
resources/. The program flow is something like this:
- A user requests
- Elgg checks if
plugin_nameis registered to a page handler and calls that function, passing
array('section', 'entity')as the first argument
- The page handler function determines which resource view will display the page.
- The handler uses
elgg_view_resource()to render the page, also passing in any relevant info to the view via the
- The resource view combines many separate views, calls formatting functions like
elgg_view_page(), and then echos the final output
- The user sees a fully rendered page
There is no syntax enforced on the URLs, but Elgg’s coding standards suggests a certain format.