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.

CommentFileSizeAuthor
#8 theme.patch535 bytesgease
#7 theme.patch440 bytesgease
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

BeatnikDude’s picture

I second this feature, I was coming to make the request myself.
Very useful module.

timb’s picture

Great module. Does what it does well, but the above feature would make it complete.

mrtoner’s picture

For those that need a snippet to do this:

global $theme;
// Replace 'garland' with the machine-readable name of your theme.
if ($theme == 'garland') {
  return TRUE;
}
else {
  return FALSE;
}

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.

klonos’s picture

Thanx 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.

Melot’s picture

I can't get this to work at all. I did exactly as you said and used this snippet:

<?php
global $theme;
if ($theme == 'bcmanga') {
  return TRUE;
}
else {
  return FALSE;
}
?>

"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.

timb’s picture

I 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.

gease’s picture

FileSize
440 bytes

Regarding 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.

gease’s picture

FileSize
535 bytes

Ok, 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:

 mymodule_init () {
  $path = drupal_get_normal_path($_GET['q']);
  if (!drupal_match_path($path, 'admin/build/*')) init_theme();
}

and giving your module lesser weight than css_injector (eg. your module - 0, css_injector - 5).

iantresman’s picture

Specifying 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.