I love that Simplenews exists - and that it works with charm!

Ive been trying to use Simplenews with Mime Mail to be able to set up different html Newsletters on one site. When trying to theme each newsletter differently and then have to use the template files for both Simplenews and Mime Mail I found that Mime Mail at first didnt get any $mailkey variable from Simplenews.

I found the issue in the queue that solves that problem, ie #324815: Pass $mailkey to Mime Mail, and I implemented the change manually (sending the $message['id'] variable from Simplenews to Mime Mail).

However, it turns out that the id is "simplenews-node ". I had thought it would be the term ID for the newsletter in question - as with regular Simplenews templates?

So, I changed the variable sent to Mime Mail:

<?php
      $message['result'] = mimemail(
        $message['from'],
        $to,
        $message['subject'],
        $message['body'],
        $plain,
        $message['headers'],
        $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
        isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
        $message['id'].'-'.$node->simplenews['tid']
      );
?>

$mailkey BEFORE my alteration:
mail-simplenews-node

$mailkey AFTER my alteration:
mail-simplenews-node-[tid]

Im not saying this is the correct way to handle it - I just want the term ID to be passed to Mime Mail for easy templating.

Comments

Agogo’s picture

And for anyone trying to name a template and having trouble - this is the way to name it with above code used:
mimemail-message--simplenews-node-[tid].tpl.php

miro_dietiker’s picture

Status: Active » Postponed (maintainer needs more info)

I don't know any other module that passes IDs into mailkey.
Pity mimemail doesn't support any context object to pass (which is missing for many drupal modules)

The intention of mailkey is primarily to know that the the origin was simplenews. Not much more.

Why do you need that alter context? Why don't you use the theming before?

Agogo’s picture

Why do you need that alter context? Why don't you use the theming before?
Can you elaborate those questions?

miro_dietiker’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev

I don't know exact limitations of 6.x-1.x features...
However note that in 6.x-2.x all .tpl.php have the full node object available.

Please help us complete 2.x. Note that 1.x is feature frozen - bugfixes only.

Agogo’s picture

Ah, thanks, well I need to be able to seperate the Mime Mail templates - not the Simplenews templates. Im guessing that full $node array isnt sent to Mime Mail?

Noted about 2.x. Mostly posted to make other users aware if they needed the same functionality as me.

miro_dietiker’s picture

Category: bug » feature

While i agree this was originally somewhat a bug, this is now a feature request.

alexkb’s picture

Agogo, thanks for sharing this.

Another sorta annoying thing is that when you do the newsletter test emails, $message['id'] is changed to "test" instead of "node" - which results in the default template file getting used. So my preference is to just return the tid, like so.

      $message['result'] = mimemail(
        $message['from'],
        $to,
        $message['subject'],
        $message['body'],
        $plain,
        $message['headers'],
        $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
        isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
        $node->simplenews['tid']
      );

Cheers.

alexkb’s picture

I should add that v2.x of simplenews is still an alpha (it was -dev when this thread was opened) - which implies its not really ready for production sites yet.

alexkessler’s picture

Thx Agogo & alexkb!
Exactly what i needed...

GBain22’s picture

Still having problems:

Hello, I wish to use different mimemail templates for different newsletters that I have, currently I have:

mywebsite.com/admin/content/simplenews/types/edit/2

So I am using the tid of 2 from the above url - my simplemail.mail.inc looks like this:

 <?php       
        $mimemail_result = mimemail(
        $message['from'],
        $to,
        $message['subject'],
        $message['body'],
        $plain,
        $message['headers'],
        $plain ? $message['body'] : simplenews_html_to_text($message['body'], TRUE),
        isset($message['params']['context']['node']->files) ? $message['params']['context']['node']->files : array(),
        $message['id'].'-'.$node->simplenews['tid']
?>

And my file is called: mimemail-message--simplenews-node-2.tpl.php

I have tried putting this in my normal theme "Clean", in my admin theme "Rubik" and also in the Mimemail module "sites/all/modules/mimemail" but it only ever uses the mimemail-message.tpl.php (it uses this from the Clean theme, or just from the module directory itself).

Is there any place I am going wrong here?

My versions are: Mimemail 6.x-1.0 and simplenews 6.x-2.0-alpha3

Agogo’s picture

Instead of using:
$message['id'].'-'.$node->simplenews['tid']

Try:
$message['id'].'_'.$node->simplenews['tid']

Should work