Product SiteDocumentation Site

4.2.3. Pages and Files

The plugin API provides a standard hierarchy and process for adding new pages and files to your plugin. For strict definitions, pages are PHP files that will be executed within the MantisBT core system, while files are defined as a separate set of raw data that will be passed to the client's browser exactly as it appears in the filesystem.
New pages for your plugin should be placed in your plugin's pages/ directory, and should be named using only letters and numbers, and must have a ".php" file extension. To generate a URI to the new page in MantisBT, the API function plugin_page() should be used. Our Example plugin will create a page named foo.php, which can then be accessed via plugin_page.php?page=Example/foo, the same URI that plugin_page() would have generated:

echo '<p>Here is a link to <a href="', plugin_page( 'foo' ), '">page foo</a>.</p>';
Adding non-PHP files, such as images or CSS stylesheets, follows a very similar pattern as pages. Files should be placed in the plugin's files/ directory, and can only contain a single period in the name. The file's URI is generated with the plugin_file() function. For our Example plugin, we'll create a basic CSS stylesheet, and modify the previously shown page to include the stylesheet:
Example/files/foo.css {
    color: red;

echo '<p>Here is a link to <a href="', plugin_page( 'foo' ), '">page foo</a>.</p>';
echo '<link rel="stylesheet" type="text/css" href="', plugin_file( 'foo.css' ), '"/>',
     '<p class="foo">This is red text.</p>';
Note that while plugin_page() expects only the page's name without the extension, plugin_file() requires the entire filename so that it can distinguish between foo.css and a potential file foo.png.
The plugin's filesystem structure at this point looks like this: