10375 Posts in 2190 Topics by 1707 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 741 Views |
-
Blog Posts in Newsletter

18 December 2010 at 4:37am
I'm trying to add my 3 most recent Blog posts into my Newsletter. The weird thing is that it works when clicking "preview this newsletter", but not in the actual emailed newsletter.
This is what I've done:
In newsletter/code/newsletter.php, I've added:
function BlogLatest($number=3) {
$holder = DataObject::get_one('BlogHolder', "Title = 'Blog'");
return DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Created DESC", false, $number);
}
And in mysite/templates/email/template.ss, I've added:<% control BlogLatest %>
<h3><a href="$Link">$Title</a></h3>
<p>$Content<a href="$Link">Read more...</a></p>
<% end_control %>I've done the usual dev/build and ?flush=all but can't understand why it would work in Preview, but not in the actual email.
Can anybody help, please? Many thanks.
-
Re: Blog Posts in Newsletter

5 January 2011 at 1:56am
Still no luck on this. I had hoped that it was just something stuck in the cache, and it would miraculously work after the Christmas break, but no such luck.
Can anyone help, please? Thanks.
-
Re: Blog Posts in Newsletter

5 January 2011 at 3:02am
The problem is that in the newsletter template you're not accessing a Newsletter object, it's an Email.
If you pull the latest branches via SVN http://svn.silverstripe.com/open/modules/newsletter/tags/rc/0.4.0-rc1 I think there's a fix in there that assigns the newsletter to a variable called Newsletter so you can write $Newsletter.BlogLatest and that should work. -
Re: Blog Posts in Newsletter

5 January 2011 at 3:29am
In fact this fix went into trunk so pull that instead.
-
Re: Blog Posts in Newsletter

5 January 2011 at 3:50am
Fantastic, thank you.
Instead of adding
function BlogLatest($number=3) {
$holder = DataObject::get_one('BlogHolder', "Title = 'Blog'");
return DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Created DESC", false, $number);
}
to newsletter/code/newsletter.php, I added it to newsletter/code/email/NewsletterEmail.php. I didn't change anything else, or even use $Newsletter.BlogLatest to call it (mysite/templates/email/template.ss remained exactly as I'd originally written it).Thank you again
-
Re: Blog Posts in Newsletter

5 January 2011 at 3:59am
If you want to keep the code in it's original state so you can update it if a new release of the module comes out you can use a decorator instead.
For example
NewsletterEmailExtension extends Extension {
function BlogLatest($number=3) {
$holder = DataObject::get_one('BlogHolder', "Title = 'Blog'");
return DataObject::get('BlogEntry', "ParentID = {$holder->ID}","Created DESC", false, $number);
}
}Then add this in your _config.php in mysite
Object::add_extension("Newsletter_Email", "NewsletterEmailExtension");
Flush everything with a ?flush=all and this should work. It's a great way of adding functionality without making changes in core files.
| 741 Views | ||
|
Page:
1
|
Go to Top |

