2

I'm using the Forward module and need help adding a custom field into the forward.tpl.php template. I've found a similar thread on d.o: https://drupal.org/node/2078479

However, this is for using user profile fields, not node fields. Here is the code that I came up with, but it's not fully working:

<?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);
?>

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...?

[Edit] Wanted to also share the code that WORKS in a node.tpl file, but not in forward.tpl:

<img src="<?php print file_create_url($node->field_main_blog_image['und'][0]['uri']); ?>" />

But, when I set this code up in forward.tpl:

$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...

1 Answer 1

0

Posted my solution on Drupal's site, the forward module issue queue:

https://drupal.org/node/2107769

1
  • Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – mpdonadio
    Commented Jan 3, 2014 at 15:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.