Functions/queue js

The queue_js() helper function is used to add script files that will be printed by display_js. This is the preferred method for both theme and plugin writers to add JavaScript to a page.

For stylesheets added with this function to be displayed, the queue_js() call must come before the display_js() call. This means you can generally call queue_js() in the following places:

Usage

<?php
queue_js($file, $dir = 'javascripts');
?>

Arguments

  • $file (string|array) (required) The name of the JavaScript file to include. You should omit the ".js" extension from the filename. You can also specify an array of filenames, and each file will be included.
  • $dir (string) (optional) (default: 'javascripts') The theme directory that will be searched for the JavaScript file. The default is the "javascripts" directory.

Return Value

None.

Output

None. display_js() is the corresponding helper that outputs the tags; all Omeka pages will normally call display_js().

Example(s)

Including a Single Script

<?php queue_js('my-js'); ?>

This will cause a call to display_js() to include a tag like:

<script type="text/javascript" src="http://example.com/omeka/themes/your-theme/javascripts/my-js.js"></script>

Including Multiple Scripts

<?php queue_js(array('js1', 'js2', 'js3')); ?>

This is equivalent to calling the above example three times, once for each stylesheet.

Source File / Version

  • application/helpers/AssetFunctions.php in Omeka 1.3.