我想知道 CSS 正在加载。因为您必须将您的库显式附加到某个渲染数组(元素、节点、页面等)。在模块的信息文件中声明它们根本不应该做任何事情。
查看有关将样式表 (CSS) 和 JavaScript (JS) 添加到 Drupal 8 模块的文档。
要将您的库加载到您必须使用的每个页面上hook_page_attachments:
<?php
/**
* Implements hook_page_attachments().
*/
function MYMODULE_page_attachments(array &$attachments) {
$attachments['#attached']['library'][] = 'saq7704/global-styles';
$attachments['#attached']['library'][] = 'saq7704/global-scripts';
// Also have a look at this gem.
// If you've written your JS file the right way you now could do
// <code>console.log(settings.MYMODULE.foo);</code> in your JS
// and guess what it will print ;)
$attachments['#attached']['drupalSettings']['MYMODULE']['foo'] = 'bar';
}
阅读如何以正确的方式编写 Drupal JS 文件:
JavaScript API 概述(注意Drupal.behaviors和)。那么你应该更好地看起来像:contextsettings*.libraries.yml
global-scripts:
version: 1.x
js:
js/scripts.js: {}
js/responsiveTabs.js: {}
dependencies:
- core/jquery
- core/jquery.once
- core/drupalSettings