By rport on
How do I include print.css to the other style sheets in page.tpl.php (see below).
<head>
<title><?php print $head_title; ?></title>
<?php print $head; ?>
<strong><?php print $styles; ?></strong>
<?php print $scripts; ?>
</head>
Thanks
Russ
Comments
Hi there
What is the path to your stylesheet ?
Suppose that print.css is, relative to index.php, in themes/myTheme/
Here is what I would do in page.tpl.php
Caroline
ps : I'd add it just after all the sytlesheets
ps2 : don't forget media="print". That tells the browser to use the stylesheet only when user prints the page...
media="screen.css"?
Don't you have to get
print $stylesto say media="screen" instead of media="all" for you themes style.css? Does anybody know how to do this?Hi there again
Oh. That's a good one.
Usually you'd have a print.css that'd override, using CSS specificity, the rules specified in other stylesheets that have
mediaset to "all".In the case where this is very hard to achieve, and you would very much prefer to start from scratch in defining CSS rules for printing, that is, you would like to set other stylesheets media attribute to "screen" rather than "all", then here's what you can do :
FIRST : Link in your print.css stylesheet in page.tpl.php (in your theme folder).
<style type="text/css" media="print">@import "<?php print base_path() . path_to_theme() ?>/print.css";</style>(It's better to use the Drupal function path_to_theme(), so disregard what I had said before.)
SECOND : Modify the function theme_add_style($path = '', $media = 'all') in includes/theme.inc, lines 331-341 (in Drupal 4.7.5).
That is the same code as in the original theme_add_style(), except that it gets a default "screen" value for media, instead of "all", in the very first line of the code above.
The function theme_add_style is not a themeing function, it cannot be overriden in template.php
Take note of the change you make in theme.inc because it's a change in core, so next time time you upgrade, your change will be wiped out. It's very much preferable to write a print.css stylesheet that can work with other stylesheets, linked "in" after the other stylesheets, using CSS specificity.
Caroline
How would this apply to
How would this apply to Drupal 6?
simple solution to including stylesheet in print.tpl.php
remove
print $print['css']from the section of your print.tpl.phpand add
<link type='text/css' rel='stylesheet' media='all' href='/sites/your_site.com/themes/your_theme_dir/your_print.css' />optionally change
media='all'
into
media='print'
that's it!
themename.info
This is a very old thread but I thought I'd put an answer here in case anyone finds it useful:
If you add the css file to your themename.info file like this:
Make sure the file actually exists, and that you clear the cache. It should appear with the other stylesheets as expected.
how would this apply to
how would this apply to Drupal 6?
In case you need to use the
In case you need to use the #attached: