Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » Custom data fields in newsletters

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

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2183 Views
  • quamsta
    Avatar
    Community Member
    29 Posts

    Custom data fields in newsletters Link to this post

    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?

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Custom data fields in newsletters Link to this post

    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

  • quamsta
    Avatar
    Community Member
    29 Posts

    Re: Custom data fields in newsletters Link to this post

    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 {

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: Custom data fields in newsletters Link to this post

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

  • mitch
    Avatar
    Community Member
    3 Posts

    Re: Custom data fields in newsletters Link to this post

    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() {
          ......
       }
    }

    2183 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.