3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1253 Views |
-
Help Email populateTemplate

29 August 2010 at 6:45am Last edited: 29 August 2010 6:45am
I'm trying to pass a DataObjectSet and using <% control MyDataObjectSet %> inside my EmailTemplate.SS but it's not working. I've also tried passing an Array and using also control blocks but still no luck. any suggestions?
-
Re: Help Email populateTemplate

29 August 2010 at 2:11pm
Could you post the code you have currently?
-
Re: Help Email populateTemplate

29 August 2010 at 5:35pm Last edited: 29 August 2010 5:49pm
<?php
class Notification extends DailyTask {function process() {
$expiringDocs = new DataObjectSet();
$newDOSet = new DataObjectSet();
foreach( $expiringDocs as $docs ) {
$member = DataObject::get_by_id('Member', (int)$docs->PersonID );
$name = $member->Surname .', '. $member->FirstName;
$record = array(
'FullName' => $name,
'Type' => $docs->Type,
);
$newDOSet ->push(new ArrayData($record));
}
$this->sendEmail($newDOSet);
}function sendEmail($data) {
$from = 'email@mydomain.com';
$to = 'customer@yahoo.com';
$subject = 'Documents Notification';
$email = new Email($from, $to, $subject);
$email->setTemplate('NotificationTemplate');
$email->populateTemplate($data);
$email->send();
}
}NotificationTemplate.ss
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html lang="en">
<head>
<title></title>
</head>
<body>
<% control data %>
<p>$FullName</p>
<p>$Type</p>
<% end_control %>
</body>
</html> -
Re: Help Email populateTemplate

30 August 2010 at 8:55am
I think the issue is that you're using <% control data %> - $data was just the variable passed to the populate template. You should pass the populateTemplate() function an array in the format of key => value like so..
$email->populateTemplate(array('MyData' => $data));
Then use <% control MyData %> in the template since that is now the name of $data.
| 1253 Views | ||
|
Page:
1
|
Go to Top |


