简体   繁体   中英

Drupal 8: Theme's css and js files are not being loaded

I was trying to create a theme for Drupal 8.1.8. My CSS and JS files unfortunately cannot be loaded. I have checked if I used any tab characters, but I have used always 2 space characters for an indent.

I have read the documentation page at Drupal.org: https://www.drupal.org/theme-guide/8/assets . I was trying around 2 hours with all possible combination. Also I tried the google search, Drupal core code inspection.. I could not figure it out.

My theme is located at themes/englishtrainer . The css is located in themes/englishtrainer/css and the javascript files are in themes/englishtrainer/js . The theme can be enabled as a theme without problems.

The contents of my theme's files in the following.

englishtrainer.info.yml:

name: Englishtrainer
type: theme
core: 8.x
version: '1.0.0'
libraries:
  - englishtrainer/base
regions:
  content: Content
  header: Header

englishtrainer.libraries.yml:

base:
  version: VERSION
  css:
    theme:
      css/css-test.css: {}
  js:
    js/js-test.js: {}

css/css-test.css:

body {
    background-color: red;
}

js/js-test.js:

alert('it is loaded!');

I was checking the html markup for any occurrences. The javascript console has been also checked. It does not contain any entries. I have cleared the entire Drupal cache and disabled/enabled the theme. Nothing helped.

Do you have any idea?

Solved it. My issue was, that I had a theme "and" a module with the same name. However the module did not implement any theming components. But this broke the theme. After I have uninstalled the module with the same name, the background was red (css worked) and the javascript alert appeared (javascript worked).

Thank you for your attention.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM