How to add custom placeholders to email templates

From aMember Pro Documentation
Revision as of 03:37, 9 August 2013 by Caesar (Talk | contribs)

Jump to: navigation, search

Add this code to site.php file:

<?php 
Am_Di::getInstance()->hook->add(Am_Event::MAIL_TEMPLATE_BEFORE_PARSE, 'mailTemplateParse');
function mailTemplateParse(Am_Event $e){
    $tmpl = $e->getTemplate();
    $tmpl->setPlaceholder("TEST");
}

Now you can use this placeholder in templates: %placeholder% it will be replaced automatically to "TEST"

Inside mailTemplateParse you can access variables which are assigned in template already. For example, if template supports %user.% or %invoice.% placeholders you can access both User and Invoice objects:

/**
 * @var User $user;
 * @var Invoice $invoice;
 */
$user  = $tmpl->user;
$invoice  = $tmpl->invoice;