Difference between revisions of "How to add custom placeholders to email templates"

From aMember Pro Documentation
Jump to: navigation, search
(Created page with "Create /amember/application/configs/site.php with this code: <source> <?php Am_Di::getInstance()->hook->add(Am_Event::MAIL_TEMPLATE_BEFORE_PARSE, 'mailTemplateParse'); function...")
 
Line 1: Line 1:
Create /amember/application/configs/site.php with this code:
+
Add this code to [[site.php file]]:
 
+
 
<source>
 
<source>
 
<?php  
 
<?php  
Line 15: Line 14:
  
 
<source>
 
<source>
    /**
+
/**
    * @var User $user;
+
* @var User $user;
    * @var Invoice $invoice;
+
* @var Invoice $invoice;
    */
+
*/
    $user  = $tmpl->user;
+
$user  = $tmpl->user;
    $invoice  = $tmpl->invoice;
+
$invoice  = $tmpl->invoice;
 
+
 
</source>
 
</source>

Revision as of 03:37, 9 August 2013

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;