0

I try to define a separate library with different name from the theme name, according to this artcle:
Adding stylesheets (CSS) and JavaScript (JS) to a Drupal 8 theme
For example a library with below details:

  • Theme name: MyThemeName
  • Library Name: Library A
  • Library File Name: libfile.info.yml

libfile.libraries.yml

LibraryA:
  version: 1.x
  css:
    theme:
      css/Style.css: {}

And then attach this library to all page in:

MyThemeName.info.yml

libraries:
  - MyThemeName/LibraryA

I would be happy to hear what the problem is, share your experiences and guide me to know what is the right way to add another library files with different name from the MyThemeName?
Thanks for any help.

2 Answers 2

2

Short answer: You cannot.

Looking answer: The purpose to for the libraries file is too define all the libraries of a module / theme.

The file is recognized because it is has the name of the theme/module it is placed at.

If you want libraries with a different namespace then you will need to search for an alter hook, and define these libraries there (not recommended).

3
  • @Eyal, what if you added that module as a dependency? Commented Oct 27, 2016 at 22:05
  • @YzmirRamirez what are you trying to achieve?
    – Eyal
    Commented Oct 27, 2016 at 22:08
  • If you made a module a depency on another then you would guarantee that module existed and you could query the settings for it or the information you need. Commented Oct 28, 2016 at 20:11
1

You're reading the module docs, the theme docs are here. The advice is identical for both though:

To define one or more (asset) libraries, add a *.libraries.yml file to your theme folder. (If your theme is named fluffiness, then the file name should be fluffiness.libraries.yml).

So if your theme is named MyThemeName, the libraries file should be named MyThemeName.libraries.yml, not libfile.libraries.yml

1
  • Thank you so much for your reply, This Question linked to the module doc by mistake, let's move on, Here is my question how can I create a library with different name from MyThemeName? Commented Oct 3, 2016 at 3:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.