Problem/Motivation
Need to include an image field in forward.tpl.php separate from the $node output... in forward.tpl.php, we have $title, $submitted, $node, and $link. I am using the "Forward Display" when managing my content type and I can include various fields here, but I need to output an image field elsewhere in forward.tpl.php
Proposed resolution
I've taken a stab at writing out the PHP and it comes close, and is probably ugly:
<?php
$path = drupal_get_normal_path($_GET["path"]);
$path = explode("/", $path);
$nid = $path[1];
$forwardthumb = node_load($nid);
$img_uri = $forwardthumb->field_thumb['und'][0]['uri'];
$fid = $forwardthumb->field_thumb['und'][0]['fid'];
$thumbfilename = file_load($fid)->filename;
$derivative_uri = image_style_path($style, $image_uri);
$success = file_exists($derivative_uri) || image_style_create_derivative($style, $image_uri, $derivative_uri);
$new_image_url = file_create_url($derivative_uri);
?>
The first few lines were conceptualized from this post:
https://drupal.org/node/2078479
I switched things from user to node, uid to nid, etc... but it's not fully working. In my testing, I've gotten the following text to output in my forwarded-email:
http://mysite.com/sites/default/files/styles/blog_thumb/public
(from the $new_image_url variable)
Which tells me that I've got it *partially* working, as it was able to indicate the correct folder / location... but I was never able to actually get it to spit out my image-file-name (e.g. thumbnail.png), just the path to the folder containing my image. Please let me know what I'm doing wrong?
Seems like part of this is a bit wonky, as it seems the $node variable in the template isn't the same $node variable used elsewhere in Drupal...?
I also wanted to share some node.tpl code that works for this, but it doesn't in forward.tpl:
<?php
$path = drupal_get_normal_path($_GET["path"]);
$path = explode("/", $path);
$nid = $path[1];
$forwardthumb = node_load($nid);
?>
And:
<img src="<?php print file_create_url($forwardthumb->field_main_blog_image['und'][0]['uri']); ?>" />
No luck... please help! Thanks!
Comments
Comment #1
nate covington commentedSolved the problem, here is the code that I wound up using.
In forward.tpl.php:
Then, in forward.module, after this line:
Add this:
And, after:
Add this:
Comment #1.0
nate covington commentedincluded node.tpl sample code that works on the actual site, but doesn't in forward.tpl email template
Comment #2
john.oltman commentedThe proper way to do this would be to write a hook_preprocess_forward function and inject new variables - then use them in your own custom forward.tpl.php