Jump to:

5537 Posts in 1737 Topics by 1223 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Adding methods to NewsletterAdmin via LeftAndMainDecorator

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

Page: 1
Go to End
Author Topic: 354 Views
  • pbz
    Community Member
    5 Posts

    Adding methods to NewsletterAdmin via LeftAndMainDecorator Link to this post

    I'm doing some work involving the Newsletter module. I basically am trying to create a newsletter template that will send the content of one of my pages, which has uses some custom methods, as part of the email. I have copied over most of the template for said page into the email template (with small modifications), but the custom methods do not work here since they are defined on a page controller (FanClubSubscriptionPage_Controller), whose methods are not available in NewsletterAdmin (where the function which sends the newsletter is located), which extends LeftAndMain. My solution is to create methods by these same names in NewsLetterAdmin by using LeftAndMainDecorator, this does not seem to work, ie the methods are not made available on NewsLetterAdmin.

    Is there is a better place to put these custom methods so they are available in both FanClubSubscriptionPage_Controller & NewsletterAdmin? That seems like the ideal solution, but not sure it's possible.

    I've experimented with extending NewsletterAdmin, but that seems impractical because a lot of the urls seem to be hard coded in, so an extension does not work properly. I've tried it.

    So I am left with thinking using a decorator to add these methods to NewsletterAdmin is the best solution, but I can't get it to work.


    class MyNewsletterAdmin extends LeftAndMainDecorator {
       public static function SpecialsAnnouncements() {
          return DataObject::get_one('FoodSpecialsPage')->FoodMenuItems('Announcement=1');

       public static function SaleAnnouncements() {
          return DataObject::get('FoodMenu', 'Sale');


    and the relevant line in _config.php

    DataObject::add_extension('NewsletterAdmin', 'MyNewsletterAdmin');

    Thanks for any suggestions.

  • pbz
    Community Member
    5 Posts

    Re: Adding methods to NewsletterAdmin via LeftAndMainDecorator Link to this post

    So apparently the problem is not what I thought it was, or at least not only what I thought it was. Dug a bit more and found that since the newsletter module uses the built-in email functionality, the templates only have available to them whatever values are made so via populateTemplate, so currently I have hacked a couple lines into NewsletterEmail->_construct.

    I can't see a better way to do this really, but if anyone has any suggestions I'd be happy to hear them.

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.