17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 2081 Views |
-
Custom data fields in newsletters

12 July 2008 at 3:55am Last edited: 12 July 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?
-
Re: Custom data fields in newsletters

14 July 2008 at 6:23pm Last edited: 18 July 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
-
Re: Custom data fields in newsletters

15 July 2008 at 3:19am Last edited: 15 July 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 {
-
Re: Custom data fields in newsletters

18 July 2008 at 3:09pm
Yes, thanks for picking up on the typo - I've corrected my original post to minimise confusion.
-
Re: Custom data fields in newsletters

30 August 2008 at 1:02am Last edited: 30 August 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() {
......
}
}
| 2081 Views | ||
|
Page:
1
|
Go to Top |



