Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I know you could do this to check for the theme in the PHP field, but it would be nice to have a select box of all themes so you could choose specifically which theme(s) on the site the snippet should be applied to when active.
Comment | File | Size | Author |
---|---|---|---|
#8 | theme.patch | 535 bytes | gease |
#7 | theme.patch | 440 bytes | gease |
Comments
Comment #1
BeatnikDude CreditAttribution: BeatnikDude commentedI second this feature, I was coming to make the request myself.
Very useful module.
Comment #2
timb CreditAttribution: timb commentedGreat module. Does what it does well, but the above feature would make it complete.
Comment #3
mrtoner CreditAttribution: mrtoner commentedFor those that need a snippet to do this:
Put that in the Pages textarea and select Add if the following PHP code returns TRUE (PHP-mode, experts only).
Much easier than putting a bunch of cruft in the module.
Comment #4
klonosThanx for the php snippet, but the use of this snippet implies that the user knows how to find the machine-readable name of a theme (and what it is I guess). So, I still think this should be implemented in the UI for non-expert users. Out-of-the-box experience and ease of use should be provided where possible.
Comment #5
Melot CreditAttribution: Melot commentedI can't get this to work at all. I did exactly as you said and used this snippet:
"bcmanga" is my themes machine readable name. And it's not that it prints the CSS in the wrong order, it doesn't print at all according to the source code. I also tried using the snippet in a regular block that's only shown on specific themes. And that DOES work! So something is wrong with CSS injector. I can get other snippets to work, and it does work if I use no code at all.
Comment #6
timb CreditAttribution: timb commentedI still would like to see this added to CSS Injector or at least to have a checkbox asking if you want it applied to the Admin Theme.
Comment #7
geaseRegarding using
global $theme
in condition. It's not availbale to css_injector, cause the injection is made early in bootstrap process, using hook_init, and theme information is loaded much later. Seems that hook_init is still the only universal hook that can be used to add css, the ideal place would be preprocess_page, but it's available only to themes.So I made a small patch that loads theme info with css_injector implementation of hook_init. I can see no harm in loading that earlier than Drupal core does, except that there is a reference to $custom_theme that some modules could define. I'm not aware of such modules and when they do define this; just for caution I would suggest increasing css_injector module weight to, say, 10.
Comment #8
geaseOk, what I've posted in #7, breaks block management (admin/build/blocks) Here's the patch that doesn't make theme initizlization for this page, but in general, this seems a slippery road. For those who need css injection by theme, I would suggest implementing hook_init in custom module like that:
and giving your module lesser weight than css_injector (eg. your module - 0, css_injector - 5).
Comment #9
iantresman CreditAttribution: iantresman commentedSpecifying a theme for a specify CSS Injector file would be very useful. I'm just about to start creating a new theme for a client, but the "old" CSS Injector file messes up everything, and I can't create a new CSS Injector file for the new theme, because it affects the old theme.