Template Tags / requireJs()
Description
Lets you include external JavaScript files without having to write <script> tags. It works like PHP's include_once, making sure that a single file is never included more than once.
Usage
<?php echo requireJs( $file, [$global] ); ?>
Parameters
$file
- required
- string
The URL to the file (can be relative or absolute, but best with absolute)
$global
- optional
- true or false
- default is false
If true, the function will look for the file in the ../site/js folder. This is useful if you need to force include default system scripts, like jQuery for example (so you don't have to have a duplicate in your theme folder, or include from another source).
Examples
Include script from theme folder
<?php echo requireJs( themeUrl() . "js/actions.js" ); ?>
Include system's jQuery
<?php echo requireJs( "jquery.js", true ); ?>