21309 Posts in 5738 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 189 Views |
-
Email Template Variable Scoping

15 September 2012 at 8:54am
Hi, have a question pertaining to the variable scope for email templates:
$mydo = new MyDataObject(); // assume prepopulated; contained a data field named "Subject" accessed by $mydo->Subject
$From = "sender@email.com";
$To = "receiver@email.com";
$Subject = "My Email Subject";
$email = new Email($From, $To, $Subject);
$email->setTemplate('TemplateEmail');
$email->populateTemplate($mydo);
$email->send();The part that I am having issues with is the dataobject's field and the declared variable "$Subject"
In my "TemplateEmail", when I tried to access "$Subject", it should be rightfully accessing the value stored in $mydo->Subject, but what I am experiencing atm is the value stored as "My Email Subject" being printed in the template instead;
The code in the template for accessing the data is simply$Subject.XML
Am I missing anything?
-
Re: Email Template Variable Scoping

15 September 2012 at 9:09am
I guess $Subject is a reserved variable for the email template to reference the actual email subject, regardless whether the variable is passed into the template.
Not sure if there's a way to override that, but I just changed the variable in my dataobject so that it doesn't name clash.
-
Re: Email Template Variable Scoping

15 September 2012 at 11:39am
I'm picking Email::getSubject() will override your Subject value on your model. A work around would be to define a getter on your DataObject
function getEmailSubject() {
return $this->dbObject('Subject');
}Then use $EmailSubject so it won't clash.
-
Re: Email Template Variable Scoping

15 September 2012 at 11:53am
Yeah, got it Will, tks for the advise.
| 189 Views | ||
|
Page:
1
|
Go to Top |


