I'm using the Printer, email and PDF versions module to render a custom print page in Drupal 7. I'd like to theme the fields individually and have worked that out to the point of using nasty php in my custom template itself.
So, I have a content type called ecard
and following the module's documentation, I'm using print--node--ecard.tpl.php
(based on the modules's core print.tpl.php
file) for my custom print template. That works fine but the usual ways of rendering individual fields like in a node template don't.
I can do this within print--node--ecard.tpl.php
to render an indivdual field called field_ecard_logo
:
<?php
$ecard_logo = field_view_value('node', $node, 'field_ecard_logo', $node->field_ecard_logo[$node->language][0]);
print render($ecard_logo);
?>
... works but kind of nasty. I'd rather put all the logic in my theme's template.php and simply print a variable I've created. Looking at what preprocess functions the Print module uses, I see preprocess_print
and preprocess_node
. So I tried this in template.php:
function MYTHEME_preprocess_print($vars) {
$node = $vars['node'];
$vars['ecard_logo'] = field_view_value('node', $node, 'field_ecard_logo', $node->field_ecard_logo[$node->language][0]);
}
and then in print--node--ecard.tpl.php
, I simply do:
<?php print $ecard_logo; ?>
but that does not work. I tried different incarnations of all this but no joy so at this point I'm stumped.