I have a problem with a custom theme I created on a Drupal 9 test site.
- Drupal version: 9.3.13
- Web server Apache 2.4.41 (XAMP win64)
- PHP version 8.0.11
- Database version 10.4.8-MariaDB
custom theme professional.info.yml:
name: Professional
type: theme
description: Drupal 9 version of Professional theme
core_version_requirement: ^8 || ^9
base theme: false
version: 1.0.0
libraries:
- professional/global-styling
- professional/global-scripts
regions:
sidebar_first: 'First Sidebar'
sidebar_second: 'Second Sidebar'
header: 'Header'
front_welcome: 'Front Welcome'
content: 'Content'
content_top: 'Content Top'
help: 'Help'
footer: 'Footer'
footer_first: 'First Bottom'
footer_second: 'Second Bottom'
footer_third: 'Third Bottom'
features:
logo: true
site_name: true
site_slogan: true
node_user_picture: true
comment_user_picture: true
comment_user_verification: true
favicon: true
main_menu: true
secondary_menu: false
custom theme professional.libraries.yml:
global-styling:
version: VERSION
css:
theme:
css/style.css: {}
global-scripts:
version: VERSION
js:
js/custom.js: {}
js/jquery.flexslider-min.js: {}
js/slide.js: {}
dependencies:
- core/jquery
- core/drupal
- core/drupalSettings
- core/drupal.dialog.ajax
I saved all the files of the new theme respecting the convention:
/site-root
- themes
- professional
- css
- js
- templates
- system
The problem is that the dependencies, including core/drupal, are not applied at all, and the three JavaScript files in the global-scripts
directive are not included in the site pages, even though both Drupal core CSS files as well as style.css from professional:global-styling
have been included.
I saw that on the chrome browser development tools console when I tried for example to show a basic page
node in a modal popup using a Drupal.org example:
<ol>
<li><a class="use-ajax" data-dialog-options="{"width":400}" data-dialog-type="modal" href="/xampp/drupal9test/node/9">Basic page displayed in modal dialog. </a></li>
<li><a class="use-ajax" data-dialog-options="{"width":400}" data-dialog-type="dialog" href="/xampp/drupal9test/node/9">Basic page displayed in non modal dialog. </a></li>
<li><a class="edit-button use-ajax" data-dialog-options="{"width":400}" data-dialog-renderer="off_canvas" data-dialog-type="dialog" href="/xampp/drupal9test/node/9">Basic page displayed in a nice off canvas dialog. </a></li>
</ol>
The node is shown as a conventional page, no modal popup is open. So neither core JavaScript nor AJAX is applied if I use my custom theme; when I switch to the Bartik theme, everything is working, modals too.
I tried adding Drupal core and AJAX libraries directly in professional_preprocess_page(&$variables)
in the professional.theme file with the line:
$variables['#attached']['library'][] = 'core/drupal';
$variables['#attached']['library'][] = 'professional/global-scripts';
I even tried to add libraries with Twig directly in the html.html.twig template with {{ attach_library('core/drupal') }}
, but none of these changes did have any effect.
Of course, every time I changed some settings I also cleared the site cache.
What am I doing wrong? Can someone give me a solution?