Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo

Custom data fields in newsletters


Go to End
Reply


5 Posts   2353 Views

Avatar
quamsta

Community Member, 29 Posts

12 July 2008 at 3:55am

Edited: 12/07/2008 4:26am

Is it possible to extend the NewsLetterType class to allow a few custom data fields in the CMS when editing the newsletter? I need a nice, user-friendly way to upload a few images of a product and then reference those images in the template file.

A few custom text fields would be nice too. Is this possible with Silverstripe? If so, how can I do this?

Avatar
Sam

Administrator, 685 Posts

14 July 2008 at 6:23pm

Edited: 18/07/2008 3:08pm

You would want to subclass the Newsletter class

In MyNewsletter.php

class MyNewsletter extends Newsletter {
... overload getCMSFields ...
... add $db information ....
}

In _config.php

Object::useCustomClass('Newsletter', 'MyNewsletter')

You will also need to make a hack to core, since it's not set up for this currently: in NewsletterEmailProcess.php, in the next function, find this code:

$e->populateTemplate(array(
						'Member' => $member, 
						'FirstName' => $member->FirstName, 
						'NameForEmail'=> $nameForEmail
					));

And change it to this:

$e->populateTemplate(array(
						'Newsletter' => $this->newsletter, 
						'Member' => $member, 
						'FirstName' => $member->FirstName, 
						'NameForEmail'=> $nameForEmail
					));

Then, in your Newsletter template file, you can reference

$Newsletter.MyVar, etc

Avatar
quamsta

Community Member, 29 Posts

15 July 2008 at 3:19am

Edited: 15/07/2008 4:20am

Thanks, I'll give this a try! Will SilverStripe incorporate this functionality better in the future?

Edit: Also, I think your instructions to subclass Newsletter are reversed

Should it be:

class MyNewsletter extends Newsletter { 

Instead of:

class Newsletter extends MyNewsletter { 

Avatar
Sam

Administrator, 685 Posts

18 July 2008 at 3:09pm

Yes, thanks for picking up on the typo - I've corrected my original post to minimise confusion.

Avatar
mitch

Community Member, 3 Posts

30 August 2008 at 1:02am

Edited: 30/08/2008 1:04am

Will this work and can I use method MyMethod in newlsetter ss template as control?
Thx.


class MyNewsletter extends Newsletter {
	......
}

class MyNewsletter_Controller extends ContentController {
	function init() {
		parent::init();
	}
	
	function MyMethod() {
		......
	}
}