I would like to add a parameter to my tpl file. I can see, for example, the list of user parameters available. I am not sure the code for getting the parameter into the email. So, if I want:

Greetings [name]!

How do I do that in the tpl.php file?

Thanks,
Maria

Comments

pillarsdotnet’s picture

Category: support » feature

You're looking for token support, I think.

mariagwyn’s picture

Hm. possibly. Or just the field code.

pillarsdotnet’s picture

Find the module that is calling drupal_mail() and look at the fifth parameter. If the calling module provides a user id, or user object, or other user-type context, then the template file can access it via the $params variable. If the calling module does not provide such info, then you might want to try something like this:

$account = user_load_by_mail($to);
$body = token_replace($body, array('user' => $account));

This of course assumes that the email recipient address is associated with a user account.

I'm probably going to mark this "Won't fix" because the above code properly belongs in the sending module's hook_mail() implementation.

pillarsdotnet’s picture

Component: Code » Documentation
Assigned: Unassigned » pillarsdotnet
Category: feature » task
Status: Active » Needs work

Okay, the above info needs to be added to documentation.

salvis’s picture

Issue summary: View changes
Status: Needs work » Closed (outdated)