10810 Posts in 2495 Topics by 1784 members
|Go to End|
21 May 2010 at 12:33pm
I have Newsletter V0.4 running well on SS 2.3.7. Subscribe, unsubscribe, my templates, and viewing and editing saved drafts is all working great thanks in no small part to the helpful advice on this forum.
I now want to add some advanced functionality to my template so that it draws info from other parts of the site automatically. For example, I would like the latest five events from my events calendar to be added to the newsletter email.
I already have this working fine on my home page (again thanks to the forums and tutorials), along with the latest news and some random content that displays a different Featured Group every time the page is refreshed.
This was simple enough to do via the HomePage.ss page type, which extends the Page.ss page type, but the same workflow doesn't seem to apply to the Newsletter module.
Can anyone give me a basic workflow on how to achieve this, or some good reasons why it cannot be done?
Is there a way to reference external PHP files with the required code from within my newsletter email template, without having to mess around with the Newsletter module code?
I've seen a few posts asking for similar advice but no real answers so I'm putting it out there again.
24 May 2010 at 8:23am
Yes this can be done but unless there's been changes made in how the Newsletter module works you'll have to make changes in the Newsletter module files. The problem is basically getting the info you want into the Newsletter template.
If we take your example of adding the latest five events from your event calendar you'll have to edit NewsletterAdmin and NewsletterEmailProcess to make sure that the extra data gets added to the newsletter.
In the case of NewsletterEmailProcess you're looking for $e->populateTemplate on line 84. In NewsletterAdmin things start at line 569. In both cases you have access to the newsletter being sent so I'd make a newsletter decorator with a method that fetches the latest 5 events and add that through
Object::add_extension("Newsletter", "NewsletterDecorator"); in _config.php
so if we assume you that you call that method getLatestEvents() you'd write
in NewsletterAdmin on line 572
$e->LatestEvents = $newsletter->getLatestEvents();
in NewsletterEmailProcess line 84 replace the current statement with
'Member' => $member,
'FirstName' => $member->FirstName,
With this you should be able to write <% control LatestEvents %> in your newsletter template to get the latest 5 events.
|Go to Top|