The js() helper function retrieves JavaScript files located within the /javascripts/ folder of a theme. By using js(), the relative path to the file is dynamically generated for each page.
Note: Starting with Omeka 1.3, the queue_js helper is preferred to this one for most use cases. Normally, you should only continue to use this helper when you want to output an inline script in the body of the page.
Usage
<?php js($file, $dir = 'javascripts', $scriptaculousLibraries = array('effects', 'dragdrop')); ?>
Arguments
- string
$file
{{#if - | (optional)}}
- The name of the JavaScript file to be included, without the .js extension.
- {{#if: | Default:
{{{default}}}
}} - string
$dir
{{#if - 'javascripts' | (optional)}}
- The theme directory where the JavaScript file is located.
- {{#if: 'javascripts' | Default:
'javascripts'
}} - array
$scriptaculousLibraries
{{#if - array('effects', 'dragdrop') | (optional)}}
- An array of Scriptaculous libraries to be included, by file name. This variable has effect only if 'default' is passed for the
$file
parameter. - {{#if: array('effects', 'dragdrop') | Default:
array('effects', 'dragdrop')
}}
Return Values
- (string) A <script> tag that includes the JavaScript file
Example(s)
Include a JavaScript file
<?php echo js('foo'); ?>
The above code includes the JavaScript file foo.js in the themes/[YOUR THEME]/javascripts directory by returning the following HTML
<script type="text/javascript" src="http://www.yourdomain.com/themes/YourTheme/javascripts/foo.js" charset="utf-8"></script>
Include the default JavaScript file
<?php echo js('default'); ?>
The above code includes JavaScript file default.js within the javascripts directory. Because it is including the default JavaScript file, the function loads the effects and drag and drop Scriptalicious libraries.
Source File / Version
- application/helpers/FileFunctions.php in Omeka 1.0.