Score:0

Adding theme JS library in custom module

pt flag

My theme documention.libraries.yml file is defined as follows :

global-styling:
  version: VERSION
  css:
    base:
      styles/dist/styles.css: {}
tocbot:
  js:
    libraries/tocbot/tocbot.js: {}
    js/tocInit.js: {}
  css:
    layout:
      libraries/tocbot/tocbot.css: {}
layout_tweaksLib:
  js:
    js/layout_tweaks.js: {}

My custom module implements a custom template which also requires the theme functionality defined in tocInit.js. So I'm trying to include the tocbot library from my theme in my module.

I have tried including a dependencies clause in my_module.libraries.yml file, resulting in the following :

my_module:
  js:
    js/my-module.js: {}
  dependencies:
    - documentation/tocbot
  css:
    component:
      css/my-module.css: {}

However, the tocInit.js script is not being loaded on the modules' custom template.

I would appreciate some help, please.

Score:0
in flag

From documentation.libraries.yml, extend the module's definition of the my_module library to include documentation/tocbot's assets using libraries-extend.

# documentation.libraries.yml
libraries-extend:
  my_module/my_module: 
    - documentation/tocbot
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.