I've implemented the code and tried to extend it with code form http://doc.silverstripe.org/doku.php?id=email. I would like to include a link to the page the comment has been made on in the email.
How can I include the page url information in the email?
mysite/code/PageCommentEmailNotification.php
<?php
class PageCommentEmailNotification extends DataObjectDecorator {
function onAfterWrite() {
$email = new Email();
$email->setTemplate('NewComment');
$email->setTo('email@ddre.ss');
$email->setSubject('New Comment ' . str_replace(array("http://", "https://"), array("", ""), Director::absoluteBaseURL()));
$email->populateTemplate(Member::currentUser());
$email->populateTemplate(array(
'Comment' => $this->owner->Comment,
));
$email->send();
}
}
?>
themes/mytheme/templates/email/NewComment.ss
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<style>
p{
font-size: 1.2em;
color: #444;
}
p.comments{
font-size: 1.4em;
color: #222;
padding: 20px;
}
</style>
</head>
<body>
// How can the page url and title be inserted here?
<p>At $Created, $Name posted a new comment on the page <a href="$Page.URL">$Page.Title</a>.</p>
<p>Their comment:<br/>
$Comment</p>
<p>You can <a href="{$BaseHref}admin/comments/">administrate the comment</a>.</p>
</body>
</html>