I've managed to get the module to use my custom template files (sort of), but I'm having a little trouble getting the related CSS to be included. So a few questions...

Does the module allow for drupal_add_css or must you explicitly reference your css file?

Do I need to include the @media definition within the CSS file?

Thanks

Comments

jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

If you call drupal_add_css() in the original node, that CSS will be used in the print output, as long as the type parameter is not set to 'theme'.

You don't need the @media.. Since the module creates a paper-suitable display in the default setting, there's no need to specify different medias.

João

gmak’s picture

João,

Thanks for the quick response. My original template does call drupal_add_css(), but the custom print template does not seem to be getting the correct css.

Both templates are in my theme folder. For example, I have:

node-assessment.tpl.php which calls node-assessment.css

for printing, I have:

print_html.node-assessment.tpl.php (this file does not include the drupal_add_css call).

But, I get the overall template structure, but none of the styles from node-assessment.css.

Any suggestions?

jcnventura’s picture

What's the value of the type parameter in the drupal_add_css() call?

gmak’s picture

there is no specified 'type' parameter in my call to drupal_add_css():

drupal_add_css(path_to_theme() .'/node-assessment.css');

jcnventura’s picture

If nothing is specified, it is type = 'module'.

However, reading it again, I would like to point out that your template file is not used by this module, so whatever PHP you do in it needs to be duplicated in the print.tpl.php file. Specifically, you need to add to write the following at the top of the file:

drupal_add_css(path_to_theme() .'/node-assessment.css');
$print['scripts'] = drupal_add_css()

This should include your CSS in the current CSS list.

João

gmak’s picture

Thanks again, for yoru help.

Let me check if I've understood this correctly:

At the top of print.tpl.php, I should add:

<?php
drupal_add_css(path_to_theme() .'/node-assessment.css');
$print['scripts'] = drupal_add_css()
?>

Yes?

If that is correct, then something is not working because the css does not get applied to print output.

However, if I manually add my css to the print.css file, then it gets applied to print output/pdf. I don't like this as a solution, because it means I have to edit multiple files when I need to change some css.

Is there something else I've not got right?

jcnventura’s picture

Sorry,

The second line, obviously should be like this:

 $print['css'] = drupal_add_css();

I copied the wrong part of the template file, and didn't check the code so well..

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No further info in two weeks. Closing the issue.

kay_v’s picture

Proposed solution doesn't work for me: I get the word "array" at the top of the body.

Here's what I put at the very top of the print.tpl.php file:

  drupal_add_css(path_to_theme() .'/print-newcss.css'); 
  $print['css'] = drupal_add_css();

I also moved this file to my custom theme folder (sites/all/theme/custom_theme).

Any suggestions?

Thanks for the VERY useful module!

kay_v’s picture

Status: Closed (fixed) » Active
jcnventura’s picture

Status: Active » Postponed (maintainer needs more info)

You're right, this doesn't work at all. You have to add the proper html to include a css file:

<link type="text/css" rel="stylesheet" media="all" href="path to css file" />

just below the $print['css'] line.

Sorry for the above suggestions, I only tired it myself now.

jcnventura’s picture

Status: Postponed (maintainer needs more info) » Closed (fixed)

No further info in more than two weeks. Closing the issue.

jlyon’s picture

I was trying to do this in a theme preprocess function, and it took me far too long to figure out, so here's the code. I hope it helps someone out. This added a lot of the CSS from my theme, but in my case that was actually a good thing.

/**
* Implements hook_preprocess_print()
*/
function hopelink_preprocess_print(&$vars) {
drupal_add_css(path_to_theme() . '/css/print.css');
$vars['print']['css'] .= drupal_get_css();
}