Drupal 9 custom theme dependencies

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 (xampp 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

but the problem is that the dependencies like "- core/drupal" are not applied at all and even the three custom js files in "global-scripts" directive are not included in the site pages, but on the opposite both the css files of Drupal core and the custom "style.css" are 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="{&quot;width&quot;: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="{&quot;width&quot;: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="{&quot;width&quot;: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 js nor ajax is applied if I use my custom theme, if I switch to Bartik theme everything is working, modals too. I tried adding drupal core and ajax libraries directly in the professional_preprocess_page(&$variables) in the professional.theme file with the line:

$variables['#attached']['library'][] = 'core/drupal'; $variables['#attached']['library'][] = 'professional/global-scripts'; 

and I even tried to add libraries with twig directly in template html.html.twig like {{ attach_library(‘core/drupal’) }} or any other libraries etc…

but none of these changes did have any effect.

Of course every time I changed som settings I cleared the site cache.

So my question is what am I doing wrong? Can someone give me a solution?

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Drupal 9 custom theme dependencies

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.