Posted by eliosh on December 15, 2008 at 12:11pm
Jump to:
| Project: | HTML Mail |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed (fixed) |
Issue Summary
By adding this two functions:
<?php
function htmlmail_theme(){
return array(
'htmlmail' => array(
'arguments' => array('body' => null),
),
);
}
function theme_htmlmail($body){
return "<html>\n" .
"<head>\n" .
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
"</head>\n" .
"<body>\n". $body ."</body>\n" .
"</html>\n";
}
?>we can use D6 theming API in this manner :
<?php
// Insert the preformatted HTML so the end user only needs to enter what goes between the <body> tags.
// this of course can be overridden in the admin settings for this module.
if (variable_get('htmlmail_preformat', '1') == 1) {
$message['body'] = theme('htmlmail', $message['body']);
}
?>Sorry for my poor english, but i think this is the quickest way to let me be understood.
Bye
Comments
#1
Up.
Yesterday a new version was deployed, but no answer to my suggestion.
I think it's a great idea, because one can put email template in a separate file, allowing full theming in a drupal way.
Thanks.
#2
eliosh, the 6.x1.0 version was deployed to make way for new developments, including theme functions.
#3
committed to 6.x-1.x-dev please confirm is workign
#4
#5
Automatically closed -- issue fixed for two weeks with no activity.
#6
Ok, i confirm that 6.x-1.x-dev works as expected.
#7
How about a back-port to D5?
#8
At the risk of throwing a spanner in the works, I needed more robust functionality than was was being provided by the original 5.x module, so I made the following modifications for my site:
<?php
$form['htmlmail_settings']['htmlmail_preformatted_options'] = array(
'#type' => 'fieldset',
'#title' => t('Options for pre-formatted HTML code'),
'#description' => t("These options apply ONLY if you've chosen 'Preformat HTML code' above.")
);
$form['htmlmail_settings']['htmlmail_preformatted_options']['htmlmail_head'] = array(
'#type' => 'textarea',
'#title' => t('<head> text'),
'#default_value' => variable_get('htmlmail_head', ''),
'#description' => t('If you want something consistently between the <head> and </head> tags, place it here. This will appear after the <meta> tag which is automatically inserted.')
);
$form['htmlmail_settings']['htmlmail_preformatted_options']['htmlmail_bodytag'] = array(
'#type' => 'textarea',
'#title' => t('<body> tag'),
'#default_value' => variable_get('htmlmail_bodytag', ''),
'#description' => t('If you want something consistently in the body tag (such as specifyign a background colour), place it here.')
);
$form['htmlmail_settings']['htmlmail_preformatted_options']['htmlmail_bodytop'] = array(
'#type' => 'textarea',
'#title' => t('<body> top'),
'#default_value' => variable_get('htmlmail_bodytop', ''),
'#description' => t('If you want something consistently at the top of the body (such as a banner image using the <img> tag), place it here.')
);
$form['htmlmail_settings']['htmlmail_preformatted_options']['htmlmail_bodybottom'] = array(
'#type' => 'textarea',
'#title' => t('<body> bottom'),
'#default_value' => variable_get('htmlmail_bodybottom', ''),
'#description' => t('If you want something consistently at the bottom of the body (such as a banner image using the <img> tag, or closing any <span> tags you may have included in the <body> top), place it here.')
);
?>
<?php
function htmlmail_mail_alter($mailkey, &$recipient, &$subject, &$body, &$sender, &$headers) {
$headers['Content-Type'] = 'text/html; charset="utf-8"';
// The paragraph an break stuff
if (variable_get('htmlmail_autop', '1') == 1) {
$body = _htmlmail_autop($body);
}
// Convert links to actual URLs. Do this before inserting the preformatting, as don't
// want to change things that may appear in <img> tags in the bodytop or bodybottom section.
if (variable_get('htmlmail_urlfilter', '1') == 1) {
$body = _htmlmail_url($body);
}
// Insert the preformatted HTML so the end user only needs to enter what goes between the <body> tags.
// this of course can be overridden in the admin settings for this module.
if (variable_get('htmlmail_preformat', '1') == 1) {
$bodyTag = variable_get('htmlmail_bodytag', '');
$body = "<html>\n" .
"<head>\n" .
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\n" .
variable_get('htmlmail_head', '') .
"</head>\n" .
"<body" . ( $bodyTag == '' ? '' : ' ' . $bodyTag ) . ">\n" .
variable_get('htmlmail_bodytop', '') .
$body .
variable_get('htmlmail_bodybottom', '') .
"</body>\n" .
"</html>\n";
}
return;
}
?>
It's working nicely for me, and it's configuration as opposed to theming (i.e., writing code).
shawn
#9