- Issue created by @giordy
- ๐บ๐ธUnited States paulmckibben Atlanta, GA
It's possible that colorbox.js is not loaded on your page, especially if you are not using anything that would actually load the colorbox Javascript.
If you're using an image filed with the Colorbox display formatter, then the javascript will be loaded. But if you're not doing that and are only relying on the colorbox class, that by itself will not load the javascript library.
If you are able to edit your theme, there are a couple ways to make sure the library gets loaded (it's the "colorbox/colorbox" library):
1. If you want colorbox to be present all the time on all pages, update your [theme].info.yml file by adding colorbox/colorbox to your libraries (and add colorbox/dompurify if you need that too):
libraries: - colorbox/colorbox - colorbox/dompurify
2. If it's only on certain templates where you will need it, you can edit the relevant twig files, e.g. page.html.twig, by placing the necessary attach calls at the top:
{{ attach("colorbox/colorbox") }} {{ attach("colorboxy/dompurify") }}
3. There are other ways to attach javascript libraries, e.g. in theme preprocessing, so if you're familiar, use the approach that works for you.
- ๐ฎ๐นItaly giordy
Thanks for the reply.
1. I have:
libraries: - colorbox - dompurify
and not:
libraries: - colorbox/colorbox - colorbox/dompurify
as in the site with drupal 10.
2. I put in the subtheme file gmpe.info.yml:
libraries: - colorbox - dompurify
but it doesn't work.
3. I tried the GLightbox module, but it doesn't work either.
I can't understand and I don't know what else to do.
Thanks and regards
- ๐บ๐ธUnited States paulmckibben Atlanta, GA
2. I put in the subtheme file gmpe.info.yml:
libraries:
- colorbox
- dompurify
but it doesn't work.Your theme info.yml file needs to have:
libraries: - colorbox/colorbox - colorbox/dompurify
- ๐ฎ๐นItaly giordy
I tried to put
libraries: - colorbox/colorbox - colorbox/dompurify
but it doesn't work.
same for me. Colorbox is no longer working since I updated to Drupal 11.0.5
- ๐บ๐ธUnited States paulmckibben Atlanta, GA
@giordy and @junk_box, I'll be glad to help further if you will please provide a set of steps for me to reproduce your problem using a clean Drupal installation.
i.e.
Step 1: Install Drupal 11.0.5 with the standard profile
Step 2: Install the colorbox module using composer
Step 3: Install the colorbox library
Steps 4..n: Each additional step for me to replicate the exact setup that is failing for you, up to the point where I click on the link that should display in a colorbox and it fails to do so.Thanks,
Paul - ๐ฎ๐นItaly giordy
- I created the new site https://nuovo.gmpe.it/ (Drupal 11.0.5) with cpanel. I can't use composer because it's not included in my hosting plan. For dependencies I use the Ludwig module.
- I installed three modules: Admin Toolbar, Ludwig, Colorbox.
- I installed the libraries: colorbox, dompurify.
- I created the page https://nuovo.gmpe.it/node/2Colorbox doesn't work.
The site https://www.gmpe.it/ with drupal 10.3.6 was created in the same way and has the same configuration. Colorbox works perfectly. See, for example: https://www.gmpe.it/micrometeoriti
- ๐บ๐ธUnited States paulmckibben Atlanta, GA
@giordy,
As I explained before, it is not enough to merely insert an image in the body field and expect colorbox to work.
You have to do something to make the Colorbox library load, such as attaching the colorbox/colorbox library in your theme, or adding a field with a display mode that uses colorbox.
Clearly, you have done something on your 10.3 site that has caused the colorbox library to load. This hasn't been done on the 11.0.5 site.
Please see my suggestions in comment #2.
- ๐ฎ๐นItaly giordy
1. I have been using this module since version 6 and I have never had any problems, nor have I ever inserted anything into the theme to make it work.
2. Even on the site https://www.gmpe.it/, with 10.3.6 I have not inserted anything into the theme (fig. A).
3. On the site https://nuovo.gmpe.it/ with 11.0.5 I cannot insert anything because the theme is in the core.
4. On the site https://prova.gmpe.it/ with 11.0.5 I inserted as in comment #2, but it does not work (fig. B). See https://prova.gmpe.it/prove
5. If I also had to modify the gmpe.info.yml file to make the GLightbox module work, it means that there is a real problem with Drupal 11.0.5 - ๐บ๐ธUnited States paulmckibben Atlanta, GA
@giordy,
As I explained before, it is not sufficient to merely insert an image in the body field and expect colorbox to work. That has been true since Drupal 8. The javascript library is only loaded under specific circumstances.
On your Drupal 10 site, you must have done something, somewhere, to cause the colorbox library to be loaded. Perhaps you have defined a field that uses the Colorbox image formatter in "Manage Display".
I and others have been able to make Colorbox work in Drupal 11 without a problem, as long the content type is properly configured with an image field that uses the Colorbox formatter. Alternatively, you can attach the libraries yourself if you are using a custom theme.
I am going to change this to a documentation issue, with an action item to provide more specific setup instructions.
- ๐ฎ๐นItaly giordy
I understand that something is needed to load the library, but this does not solve my problem.
- I have an image in a node
- I modified the gmpe.info.yml file as indicated in point #2What is still missing for it to work?
Maybe the Colorbox Inline module is needed, which does not exist for drupal 11?Thanks
For me it works now. All I changed was my view. I changed it from Bootstrap Grid to the Drupal core responsive Grid. My view field is still set to content: Image (formatter colorbox).