Please post what you've gotten to work in the way of Email Templating for "Send to a Friend"

Personally, I've had no luck creating a template using the Email Template entry field provided inside the SendModule menu selection.

I've searched high and low and have seen others post questions about color etc. For me, I would just like to create something tablelized that is delivered in the center of the screen.

I notice the message arrives with a great deal of formating instructions which I have read is from my theme (I use Garland Fluid). But how do I tell Send to turn that off?

I'd like to start a thread where people post what they've gotten to work so we can all learn and therefore Send becomes easier to use.

I will take on the responsibility to compile all posts into a sort of user tip guide.

Cheers!
Cozmo

Comments

stevensurowiec’s picture

The reason for this if I remember correctly (do not have the module in front of me) is that the module passes the email body through theme('page').

cozzi’s picture

That's what I thought from reading another post somewhere.

Is there an easy way to stop that from happening therefore giving the "Email Template" entry field the power you expect it to have?

stevensurowiec’s picture

You would need to find where, in the code, this is happening and modify it. I can look into writing a patch that adds an option to the administration for this later tonight or tomorrow but it may take a couple days to get done due to time constraints.

cozzi’s picture

That would be fantastic. I've been living with it for a few weeks now (since I found and turned on the module) and can certainly live with it for a few more days - especially given that it would probably take me days just to find the code you suggest I comment out.

stevensurowiec’s picture

After investigating this further it does not go through theme('page') it goes through theme('send_body') so if you make an override for this in your theme file then you should be able to change the theming of the body. The theme_send_body function is below.

function theme_send_body($values) {
  $body = '';
  $template .= $values['template'];
  if ($values['message']) {
    $message = '<div class="messages">'.check_markup($values['message']).'</div>';
  }
  $body = $values['node_body'];
  $replace = array('%message', '%body');
  $values  = array($message, $body);
  
  return str_replace($replace, $values, $template);
}
cozzi’s picture

Before I asked any questions with obvious answers, I wanted to try and get your suggestion to work myself, but I can not.

What is it you want me to with the above function? I have located it in send.inc and have tried commenting out sections of theme_send_body but have not gotten any good results. To find it I searched all files for the string theme_send_body and only found it once (in the form of the function definition) inside send.inc.

I am thinking you want to me comment out either something in the theme_send_body function OR comment out something in the code that calls theme_send_body - but I can not locate any other module looking to call theme_send_body?

Sorry, I've not done any real programing in many many years so please help me with just a bit more detail on what you mean by "make an override this in your theme file"?

Thank you again for your help.

Best Regards
Cozzi

cozzi’s picture

I'm still stuck on this. Can I please get just a bit of help as to what I'm suppose to do next?

thank you in advance

cozzi’s picture

Maybe I'm doing something blindingly incorrect?

Maybe I'm going about this all wrong? If my Send emails are being sent with all the theme formating should not the delivered email "look" like my site? You know, top nav with the logo, left and right navigations with the blocks. If this were the case I would probably like what is delivered BUT right now the delivered message "only" contains the node being sent (with sender's text included) - it just looks so bare.

So, my basic question - should the Send Module be sending the node AND the top, left, right, and footer blocks? If so, have I configured something incorrect?

this could be the key to my problem.

thank you again.

stevensurowiec’s picture

The following page has information on creating and using a template.php file.
http://drupal.org/node/11811
Once this file is created you would need to create the function I posted in that file with the name [theme]_send_body where [theme] is the name of your theme (ie - garland). This function gets passed a parameter called $value and returns the actual HTML display of the email. By overriding this function you take away the module's themeing of the email body and do it all yourself.

cozzi’s picture

Thank you for the added details - I will try this.

I really appreciate the extra effort here.

Cozmo

buddhahara’s picture

buddhahara’s picture

I would like to change the template if possible without modifying the underlying code if possible. I am wondering what variables can be used in addition to %message and %body. Basically, I would prefer to send people a teaser and a link to the full article or maybe even just the link. The idea is to use send to drive people to the site versus send the site to them. :)

thanks

allie micka’s picture

I'm open to ideas ( and patches ! ) for getting more tokens into the send message templates.

One thing to keep in mind, however, is that Send is capable of sending multiple nodes in a particular message. Therefore, it gets a little messy to contemplate having %link_to_node or %node_title, etc.

You can always disable the "allow sending of full text" item to restrict sent node(s) to a teaser view.

cozzi’s picture

I’m sorry, but I just can’t seem to get this override to work for me. Here’s what I’ve done:

1) I found the file template.php (it already existed) in my folder ../theme/garland (I use garland as my theme)

2) I added the function you posted to the bottom of this template.php

function garland_send_body($values) {
$body = '';
$template .= $values['template'];
if ($values['message']) {
$message = '

'.check_markup($values['message']).'

';
}
$body = $values['node_body'];
$replace = array('%message', '%body');
$values = array($message, $body);

return str_replace($replace, $values, $template);
}

When testing Send to Friend the email delivered still comes with a blue background (the same color as my theme’s left and right nav) and when I view source of the email there is a lot of html markup that seems to be theme related. (same as the original post)

I also tried this process again after upgrading to the new build of Feb 25.

Now, I might be missing something, because as I’ve re-read your instructions numerous times over the past two weeks and still can't get it but there is one statement I’m not 100% sure of. What do you mean by this – “By overriding this function you take away the module's themeing of the email body and do it all yourself.” Does this mean I am suppose do something additional to the function you posted to get the override to work?

Thanks in advance

MauMau’s picture

Title: Email Template entry field - what works for you and how » Don't bother with templating

In send.inc line 592 it says

case 'teaser' :
        $text =  node_view($node, true, false, false);

If you change that to

 case 'teaser' :
        unset ($node->taxonomy); 
        $text =  node_view($node, true, false, false);

the teaser will still get sent. But the receipient will not have to look at taxonomy links.

You can up the ante and go

 case 'teaser' :
        unset ($node->taxonomy); 
        $text =  "Something " . node_view($node, true, false, false) . " Something else";

If you're used to do Drupal templating you might go

 case 'teaser' :
        $text =  $node->title . "<br />" . $node->teaser;

You can play the same tricks on case 'body' in line 598.

node_view is the function that loads the teaser or body text that you so desperately want to alter
http://api.drupal.org/api/function/node_view/5

Unset will be your best friend.

cozzi’s picture

Allie: Is there any chance you could give us a "one" click checkbox to tell Send to "by-pass" all templating therefore giving all layout control to the Email Template field provided in the Send to Friend configuration area? You could put this checkbox just before the Email Template configuration field.

Is this possible? (Honestly, I have no idea to how to code it or I would help. I'm asking this question on behalf of the many non-coders that really struggle with things (seamingly simple to a programmer) such as the instructions I've been wrestling with above.)

Thank you in advance
Cozmo

amiable_indian’s picture

Thanks this thread helped me in creating my own template for `send` module... I am a newbie to drupal but with few clicks and play around with api , I was able to get this working.

1. go to your theme folder
2. add the following function to your template.php

<?php
/*Templating for Send Module*/
function YOURTHEME_send_body($values) {
  # send module can email multiple nodes, but my implementation sends only one.. 
  # so this hopefully not break anything, node_load function will grab all other details for the 
  # node that the user is emailing
  $node_details = node_load($values['nids']['0']);
  ## Adding my site banner 
  $body = '<hr /><img src="http://YOURSITE.com/logo.gif" /><br />';
  ## adding node title
  $body .= '<h2><a href="http://YOURSITE.com/'.$node_details->path.'">'.$node_details->title.'</a></h2><br/>';
  ## adding full body, you might change this to only teaser
  $body .= $node_details->body;


  $template .= $values['template'];
  if ($values['message']) {
    $message = '<div class="messages">'.check_markup($values['message']).'</div>';
  }
  $replace = array('%message', '%body');
  $values  = array($message, $body);
 
  return str_replace($replace, $values, $template);
}
?>

3. For testing, I used the following code. Its helpful when you have complicated CCK fields and want to debug your code. If you use gmail , use the "show original text" to see the actual values of the array.

<?php
/*Templating for Send Module*/
function YOURTHEME_send_body($values) {
  $node_details = node_load($values['nids']['0']);
  ## just dump everything into email body
  $body = print_r($node_details,TRUE);

  $template .= $values['template'];
  if ($values['message']) {
    $message = '<div class="messages">'.check_markup($values['message']).'</div>';
  }
  $replace = array('%message', '%body');
  $values  = array($message, $body);
 
  return str_replace($replace, $values, $template);
}
?>

Best way to tackle theming problem with 'send' module would be to have something like 'ConTemplate' :-)

HTH,

~Amiable_Indian

jerdavis’s picture

Status: Active » Closed (fixed)

Thanks so much for the great example Amiable! I've added this to a handbook page for Send http://drupal.org/node/291748

steveoliver’s picture

Thanks for the function. I found that $body .= $values['node_body']; actually prints the node body while $body .= $node_details->body; returns nothing.