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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

All other Modules /

Discuss all other Modules here.

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

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


Go to End


2 Posts   1842 Views

Avatar
novaweb

Community Member, 116 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
dhensby

Community Member, 253 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.