Download & Extend

Use theme function to render body

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

Status:active» fixed

#5

Status:fixed» closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.

#6

Ok, i confirm that 6.x-1.x-dev works as expected.

#7

Version:6.x-1.x-dev» 5.x-1.x-dev
Status:closed (fixed)» patch (to be ported)

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:

  1. In function htmlmail_admin(), included the following right before the 'return':
    <?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('&lt;head&gt; text'),
             
    '#default_value' => variable_get('htmlmail_head', ''),
             
    '#description' => t('If you want something consistently between the &lt;head&gt; and &lt;/head&gt; tags, place it here.  This will appear after the &lt;meta&gt; tag which is automatically inserted.')
              );

           
    $form['htmlmail_settings']['htmlmail_preformatted_options']['htmlmail_bodytag'] = array(
             
    '#type' => 'textarea',
             
    '#title' => t('&lt;body&gt; 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('&lt;body&gt; 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 &lt;img&gt; tag), place it here.')
              );
       
           
    $form['htmlmail_settings']['htmlmail_preformatted_options']['htmlmail_bodybottom'] = array(
             
    '#type' => 'textarea',
             
    '#title' => t('&lt;body&gt; 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 &lt;img&gt; tag, or closing any &lt;span&gt; tags you may have included in the &lt;body&gt; top), place it here.')
              );
    ?>
  2. Then, in function htmlmail_mail_alter, I altered it as follows:
    <?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

Status:patch (to be ported)» closed (fixed)
nobody click here