# vim myexample.libraries.yml
this_is_test_lib_name:
version: 1.x
css:
theme:
css/myexample.css: {}
js:
js/myexample.js: {}
dependencies:
- core/jquery
- core/drupalSettings
# vim myexample.module
<?php
/**
* Implements hook_preprocess_page().
*/
function myexample_preprocess_page(&$variables) {
$variables['#attached']['library'][] = 'myexample/this_is_test_lib_name';
}
?>
# vim myexample/js/myexample.js
(function ($) {
console.log('ready');
})(jQuery);
or
(function ($, Drupal, window) {
console.log('ready');
})(jQuery, Drupal, window);
Note: underscore.js and backbone.js are in core in Drupal 8.
Note: One other change you may have noticed: Drupal.settings is now drupalSettings.
Reference:
http://atendesigngroup.com/blog/looking-at-drupal-8-javascript-changes
No comments:
Post a Comment