If you would, I'm requesting that you insert the following code just under line number 199 in the subscriptions_mail.module.
$mailvars['!bodiecount'] = count($user_mails['bodies']);
It is rather harmless otherwise, but this code enables the mail templates to have an additional !bodiecount token containing the number of digest items in each email. One can use this number to modify the templates to show a column of ads to the right of the content roughly equal in height to the amount of content on the left, in a 2 column email template.
( I manually modify the subscriptions_mail.templates.inc file to suit my template needs)
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | subscriptions_mail.templates.inc_.txt | 12.22 KB | gregarios |
| #8 | subscriptions_mail.cron.inc.648600.8.patch | 3.82 KB | salvis |
| #3 | subscriptions_mail.templates.inc_.txt | 10.73 KB | gregarios |
Comments
Comment #1
gregarios commentedI somewhat take back my request... I thought I could read the number stored in the token and derive a token "if/then" kind of setup for displaying one, two, or three ads depending on the number of teasers in the digest content of each email. I can't seem to get this to happen, as it seems you can only check for the existence of the token content in this situation? Anyone who has any pointers, I'd love some help figuring this out.
Comment #2
salvisAdding that variable is certainly possible. However, you can only compare using == and !=, and I don't think you can nest the conditionals. (If at all, the chances are better in the 'else' part.)
If/then with one, two, or three should certainly work, but I don't see a good way to get 'four or more'...
Maybe a hook_subscriptions_digest(&$user_mails) and a convention that we'd merge $user_mails['mailvars'] into $mailvars would be a more flexible solution? That would allow you to define whatever variables you like.
Comment #3
gregarios commentedI believe, yes. I must admit I'm in a bit over my head with this... However, having a variable that I can use in the
subscriptions_mail.templates.incfile would be the best, since that is the only file from Subscriptions which I've modified. (I'd like to keep it that way.)Attached is my heavily modified file. If you could see fit, would you take a peek, and maybe tell me how I can incorporate a conditional variable that would allow me to define the 'ADS' case containing 1, 2, or 3 ads depending on that variable?
Comment #4
gregarios commentedComment #5
salvisYou'd have to do a bit of PHP programming to take advantage of such a hook.
Essentially, you'd write a Drupal module with a function that receives the $user_mails array, you'd count the bodies (or whatever) and you'd set $user_mails['mail_vars']['!number_of_ads'] to whatever you want. Then you could use that variable in your digest template.
Comment #6
gregarios commentedOk... I just made some headway. My original request stands. The token I can use, albeit a round-about way of doing it, its the only way I understand it at this point. If you could add it, it may not be useful to anyone else, but it SURE would help me with this.
Comment #7
salvisWe'll do a hook and I'll help you with it...
But it'll take a while. Please nag me in three weeks if I haven't done it by then.
Comment #8
salvisBe sure to try this on a test system — it's completely untested.
Apply the attached patch to the -dev version.
Then create a mysite module for your site:
Create mysite.info
and mysite.module
Put the files with the other contrib modules (usually sites/all/modules/mysite) and enable the module. Then you should get a new !digest_count variable.
Gook luck!
Comment #9
gregarios commentedThe patch causes no errors from what I can see, and emails do still go out.
I did the instructions you gave, then I took my
subscriptions_mail.templates.inc_.txtfile and modified it as the attached file, but it doesn't seem to show the 2nd, 3rd, etc ads inline like it does if I do the Line199 code addition. Maybe I'm not using this variable correctly, as I seem to be using it like a token still... but... I'm not sure how to get this right. Please forgive my ignorance in this matter, as I've had no formal PHP training.If I insert the
!digest_countvariable directly into the template, I only get the actual "!digest_count" text in the email.Comment #10
gregarios commentedEgads... I just realized that you are already using the
!digest_countvariable in another part of the module to count digest emails, not digest bodies...Update: changing the variable name in my custom module and the template made no difference.
Comment #11
salvisThat's completely unrelated and does not interfere.
There should not be any underscore after ".inc"!
Did you create and activate the Mysite module? If you changed "Mysite", then did you change it wherever it occurs?
Do you by chance have the Devel module installed? Then you can change
to
Now, when you run cron manually, you should see the mailvars array twice, with the !digest_count variable inserted the second time.
Comment #12
gregarios commentedAh... I'd missed renaming the "mysite" in the function name... retesting now...
Update: THAT works! :-)
2 Questions:
1) How does your way of doing this add more functionality for me?
2) Should I start a different 'feature request' to ask if there is a way we can externalize the
subscriptions_mail.templates.incfile functionality so I don't have to hack anything in the Subscriptions module to get my custom template to work? The reason I resorted to hacking the default template was the Mail Editor module was not working.THANK YOU for so much work! This has been invaluable for me, and I've learned quite a bit as well.
Comment #13
gregarios commentedComment #14
gregarios commentedLooks like this person is having the same issues I was with Mail Editor not working right: http://drupal.org/node/651304
Comment #15
salvisIt's a general mechanism that lets you or anyone else add (or change!) any number of !variables programmatically without hacking. It's an opportunity for customizing Subscriptions by adding just the minimum amount of code required. It's the preferred mechanism throughout all of Drupal to do such customizations — THE Drupal Way.
This hook is for digests and I intend to add similar hooks for non-digest notifications and comments.
Yes, please.
You're welcome. Are you ready to jump into PHP programming yet?
Comment #16
gregarios commentedOh... I already dove in. It just takes a while to learn. Perl seemed a lot easier to me in many ways. :-)
Comment #17
salvisGreat! :-)
What do you find difficult in PHP over Perl?
Comment #18
gregarios commentedWell, that's where the lines are fuzzy for me. Sometimes I'm not sure what items are PHP specific and which are Drupal specific... Perl is Perl, even in apps. But, because I'm learning PHP while learning Drupal, it is confusing... Also, Perl has a definite barrier between it and the HTML, where as PHP can be mixed in with the HTML a lot more.
PS: Any idea when this will be rolled into another release version?
Comment #19
salvisAt the theming level yes, but at the module level there's no HTML. There's a strict separation between those two levels.
BTW, Devel is your friend, and especially the dpm() function; it's easy to quickly insert anywhere and shows you what data you're dealing with. For heavy lifting, a debugger that let's you break on any given line and inspect variables is indispensable.
Probably by the end of the year.
Comment #20
gregarios commentedAny idea when this might get out in a real release? :-) I've been using my custom module with the dev version for awhile now and it works wonderfully. :-)
Comment #21
salvisThank you for the feedback, that's nice to hear.
I've committed it to the -dev version. Give it up to 12h to be repackaged.
Please check it out and let us know if it still works. Then we can release 1.2.
(If you wish to keep a backup of the old version, be sure to move it OUT FROM BELOW the Drupal directory tree!!!)
Comment #22
gregarios commentedThe Feb 3rd 6.x-1.x-dev release works great! :-) Thanks Salvis.