The only JS library that ships with Craft (besides the Craft-specific Garnish) is jQuery. Of course, jQuery is a helpful JS library, but by no means a full-fledged framework. Fortunately, adding a separate JS library is painfully easy!
How to CDN from a Twig template...
{% includeJsFile '//full/path/to/cdn.js' %}
How to CDN from PHP...
craft()->templates->includeJsFile('//full/path/to/cdn.js');
When you use includeJsFile
, it wraps your path in a standard <script>
tag... It doesn't matter where the file is, as long as the path is valid.
Keep in mind, a PHP call will take effect in both the back-end and front-end of your site. So to keep the file loaded only in your CP, make sure to wrap a conditional around it:
if (craft()->request->isCpRequest()) {
craft()->templates->includeJsFile('//full/path/to/cdn.js');
}
Don't want to CDN? No problem! The best place to store local JS files would be in a resources
folder:
/craft
/plugins
/myplugin
/resources
/js
/handlebars.min.js
In that case, you can use includeJsResource
instead of includeJsFile
.
craft()->templates->includeJs()
to inject the raw HTML template on pageload, before compiling it in my plugin's JS without $.html()'ing myself to death :) Just wondering if Craft ships with any JS templating functionality, or if I'd need to include Handlebars, Underscore or the like with my plugin.