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.

All other Modules /

Discuss all other Modules here.

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

Extending Newsletter.php to enable extra fields and a $has_one('Image')


Reply


2 Posts   1458 Views

Avatar
novaweb

Community Member, 115 Posts

29 September 2009 at 2:52pm

Hey Hey SilverStrippers,

We've been working on extending newsletter.php so we can add an image, link and one other textfield to the newsletter.

We've successfully extended the $db array and likewise with the CMS fields, the problem is - when we call them from our template - they don't show.

I'll just use the image as an example:

Newsletter.php line 23

   static $has_one = array(
      "Parent" => "NewsletterType",
      "NewsletterImage" => "Image"
   );

Newsletter.ss

<div id="Newsletter">
$Body

$NewsletterImage

</div>

Is there something extra we need to do? ... Do we need to apply some code to "class Newsletter_Email extends Email " at the bottom of Newsletter.php?

KThxBye

Avatar
Pigeon

Community Member, 243 Posts

29 September 2009 at 10:39pm

Hey, Unfortunately i'm not a SilverStripper... But i will try to help :P

Perhaps try defining a method in the Newsletter.php, eg:

function NewsletterImage() {
return DataObject::get_one('Image','ParentID = '.$this->ID);
}

(or to that effect) and then $NewsletterImage should work in the template... Although i know the Newsletter module isn't quite as easy to manipulate in this way.