queue_js_file — Add a local JavaScript file or files to the current page.

Asset-related functions

Summary

queue_js_file($file, $dir = 'javascripts', $options = array(), $version = OMEKA_VERSION)

Add a local JavaScript file or files to the current page.

All scripts will be included in the page’s head. This needs to be called either before head(), or in a plugin_header hook.

Parameters:
  • $file (string|array) – File to use, if an array is passed, each array member will be treated like a file.

  • $dir (string) – Directory to search for the file. Keeping the default is recommended.

  • $options (array) – An array of options.

  • $version (mixed) – Version number. By default OMEKA_VERSION.

Usage

head_js actually outputs the scripts. All themes should already call head_js themselves, so you can just use the queue functions.

If writing a theme, queue_js_* functions must be called before the call to head_js. If writing a plugin, you make these calls within the admin_head or public_head hooks.

The $options array is passed as the $attrs parameter to the Zend Framework headScript helper. This can be used to set some attributes on the <script> tag as well as to enable some specific functionality of the ZF helper like IE conditional comments.

Examples

Load one javascript file from the default ‘javascripts’ folder within the theme directory:

<?php queue_js_file('my_js_file'); ?>

Load two javascript files from the default ‘javascripts’ folder:

<?php queue_js_file(array('my_js_file', 'another_js_file')); ?>

Load one javascript file from the default ‘javascripts’ folder with a conditional statement:

<?php queue_js_file('my_js_file', 'javascripts', array('conditional' => '(gte IE 6)&(lte IE 8)')); ?>

See Also