forum_loader

Introduced in PunBB 1.4.0, the forum_loader class is the preferred method for including custom javascript and CSS with your extensions. Extension developers no longer need to manually construct and insert <link> and <script> tags, please use forum_loader instead.

Adding CSS

Quick Example

The following example1) demonstrates a safe way to use the forum_loader to include your extensions CSS file for the user's selected theme, or the default theme. It assumes you already know how to use the $ext_info and $forum_user arrays.

<hook id="hd_head"><![CDATA[
	if ($forum_user['style'] != 'Oxygen' && file_exists($ext_info['path'].'/style/'.$forum_user['style'].'/style.css'))
		$forum_loader->add_css($ext_info['url'].'/style/'.$forum_user['style'].'/style.css', array('type' => 'url'));
	else
		$forum_loader->add_css($ext_info['url'].'/style/Oxygen/style.css', array('type' => 'url'));
]]></hook>

If you only need to add a single CSS file for your extension, just use the hook in this example. You will need to have a CSS file appropriate to the Oxygen theme at /style/Oxygen/style.css under your extension directory, and any other theme appropriate CSS files in their respective folders.

add_css Method

forum_loader provides several options for customizing the way CSS is added to the final page. The method for adding CSS is add_css, and the signature is as follows:

add_css($data = NULL, $options = NULL)

add_css Options

The following is a list of the available options for the add_css method and their defaults.