Hi,
For my site I used the sections module to have different layouts for different groups of pages (sections). Each section has its own theme, with its own templates and its own stylesheet.
Mainly when surfing in IE, there's a delay when displaying content in the right style. This is because the stylesheets are treated as if they are different: every theme has its own stylesheet, stored at different locations.
However, since the stylesheets for all the themes are the same (the differences in layout are defined in templates only), I want to solve this by using just one shared stylesheet. The idea is to stored this as "/themes/styles/style.css" or something.
Question:
How can I refer to this -one and only- stylesheet (which is not stored in the theme directory!), just with the template as starting point (or the database, may be)?
The only code that has to do with this is: print $head print $styles
So I'm mainly wondering where to change $styles.
Thnx
Marc
PS
I already tried to import the one and only stylesheet into the stylesheet that is stored in the default directory, but -of course- this does not make any difference in performance: I just want to skip the default stylesheet.
Comments
Link to style sheets
The print $head statement generates the html code which link to the "misc/drupal.css". (And code for rss functionality) The print $styles generates the code which link to the
styles in the directory of your theme.
You could remove the second statement and put the link to your style sheet manually.
For some other reasons I've did this on my site.
--
go with us - learn php
--
mdwp*
So: just delete $styles, and add a separate import?
Hi Meinolf,
Thanks for your reply and explanation about the code.
I thought about such a sulution as well. But usually I'm not a big fan of hard coded changes like this - therefore my post in the forum.
Anyway, I watched the code of your site. If I'm right, I can just delete the $styles part, and add a separate import rule for the additional stylesheet? Well, let's give it a try!
Cheers,
Marc
___________________
discover new oceans
lose sight of the shore
hard coded changes
I'm also no fan of hard coded changes. But these changes are only in a theme, not in the core or module code.
And sometimes I can't see another possibillity.
For example: in my theme I don't need the 'mics/drupal.css'.
So, why I should link to 9Kb of no needed code.
I drop the line and add the links for the rss functionality manually.
Works perfect and I got a better result with Firefox "View Speed Report".
--
go with us - learn php
--
mdwp*
another option: edit file /includes/theme.inc
Hi Meinolf,
Just tried to dig a bit deeper into the Drupal code to see if there was another option to solve my problem. Well, I've found a file called includes/theme.inc. In this file you can find the code:
if (file_exists($stylesheet = dirname($themes[$theme]->filename) .'/style.css')) {
theme_add_style($stylesheet);
}
I just replaced this part with:
if (file_exists($stylesheet = 'themes/styles/style.css')) {
theme_add_style($stylesheet);
}
Seems to work. Advantage: just one change will affect all the themes at once. Disadvantage: it's a change in Drupal's core, so I have to document this very well! Otherwise I won't be able to find it back anymore :-\
Just therefore I might stick with your solution. Anyway, just wanted to let you know...
Cheers,
Marc
___________________
discover new oceans
lose sight of the shore
Another option
I was looking at how to do this. I didn't like the options given above for the following reasons
Option 1 requires removal of a piece that is used by modules and core. Some modules add their own theme, and they would then need to be connected manually...
Option 2 requires editing core. I've done that on other projects I've worked on, and don't like it.
So I did some digging and found another option. In your template.php use
drupal_set_html_head(theme('stylesheet_import', base_path() . 'themes/style.css'));
drupal_set_html_head(theme('stylesheet_import', base_path() . 'themes/theme/style.css'));
The first sets your new theme. The second overrides your current theme. I have some slight variations, so the second is really the variations (colors change between the sites).
Thanks,
Jason