CoolBrew User Guide Version 1.3
Based on CodeIgniter Version 1.5.4


Collector Module

This module gives you access to the Collector class from your website documents. The Collector class contains functions that collect and consolidate both JavaScript and Cascading Style Sheets (CSS).

For more information about the methods accessed by these tags, please see the Collector Class section of this user guide.

Using the Collections

Normally, you'll want to collect all the JavaScript and CSS data as early as possible so it can be used in the head section of your document. For that to work, all the tags that contribute JS or CSS to the collection need to be run before the header is completed. Many times, the only way to do that is to store the results of the tag in a variable to be displayed later on the page:

<?php
require_once 'coolbrew.inc.php';

$return = TRUE;
$submenu = get('menu.submenu', 'home', $return);

$hdr['title'] = "This is the title";
$hdr['js'] = get('core.collect.wrap_js');
get('core.view.load', 'header', $data);

?>

<div id="submenu">
<?=$submenu?>
</div>

In this example:

  1. We run the fictional menu.submenu tag at the top of the page because we know that the tag adds some JavaScript code to the JavaScript collection. Since we don't want to display it where the tag is, we specify that we want the results returned instead of displayed and we store it in the $submenu variable.
  2. We gather the JavaScript collection (which will include the JavaScript from the menu.submenu tag) using the core.collect.wrap_js tag and send it to the header template.
  3. We display the $submenu HTML that we saved earlier.

The collection can be returned to your page and then sent to a view file as shown above, or you can load the data directly from inside your view files:

<?=$this->collector->wrap_js();?>

Adding Code From a File

<?php get('core.collect.append_js_file, 'file'); ?>

Adds the contents of file to the JavaScript collection.

<?php get('core.collect.append_css_file, 'file'); ?>

Adds the contents of file to the CSS collection.

Adding Code Directly

<?php get('core.collect.append_js_code, 'code'); ?>

Adds supplied code to the JavaScript collection.

<?php get('core.collect.append_css_code, 'code'); ?>

Adds supplied code to the CSS collection.

Getting the Collected Data

<?php get('core.collect.wrap_js, 'wrapper'); ?>

Returns the JavaScript collection wrapped in HTML <SCRIPT> tags.

<?php get('core.collect.wrap_css, 'media', 'wrapper'); ?>

Returns the CSS collection wrapped in HTML <STYLE> tags.

Other Utilities

<?php get('core.collect.get_js_file, 'file'); ?>

Returns the contents of the javascript file.

<?php get('core.collect.get_js'); ?>

Returns the JavaScript collection without wrapping it first.

<?php get('core.collect.get_css'); ?>

Returns the CSS collection without wrapping it first.