Hi,
I have been trying to find a solution to a presentation problem on a website we are building and I think the best solution is via css.
The "problem" lies in the best method to overwrite the css that drupal and the theme spits out.
It seems that drupal is quite rigid in the order of the stylesheets it shows in the head tag on each page.
The CSS Injector module didn't work for us as the stylesheet it created came before the others drupal spits out and thus it was overridden. Therefore the css changes we wanted to see never appeared.
I then found out about drupal_add_css and the fact that I can paste this code into a page once the php code input format has been set:
// Repeat this line for every CSS file added.
drupal_add_css(path_to_theme() . '/examplecssoverride.css', 'theme', 'screen', TRUE);
// Reassemble the $styles snippet to include the new files.
$styles = drupal_get_css();
By using 'screen' instead of 'all' I can get this new stylesheet referenced above to appear last in the head section of the page.
In this way I can create a whole bunch of little css files and if I want to use one of them as a final override, I can call it up using the above php snippet when creating content.
(Different pages need little bits of modification, such as altered page backgrounds etc, and this is the only solution I have been able to come up with that seems to work, without creating lots of new .tpl.php files).
I just wanted someone to verify that this is ok to do and the above code is not a security risk.
Or is there a better way to rearrange the order of the css files?
I am the only person who has privileges to use the php code input format.
Can you please advise.
Thanks,
Sam
Comments
The code looks ok. If you are
The code looks ok. If you are using the css injector module, you may want to see this: http://drupal.org/node/455426
Hi, So would it become the
Hi,
So would it become the following in CSS Injector's coding:
drupal_add_css(file_create_path($css_rule['file_path']), 'theme', $css_rule['screen'], $css_rule['preprocess']);Thanks,
Sam
It is possible to add a class
It is possible to add a class (or classes) to the body tag based on the path which in my opinion is a simpler option. Some themes already do this.
Can you shed a little more
Can you shed a little more light on this please?
The theme we have created already has the following in page.tpl.php
<body class="<?php print $body_classes; ?>">Thanks,
Sam
Which theme is it based on?
Which theme is it based on? Or how are you setting $body_classes?