I am loading my mail template like this:
$mailTemplate = Mage::getModel('core/email_template');
$myTemplate = $mailTemplate->load($templateId);
Now I can get the template content using:
$text = $myTemplate ->getData('template_text');
This works, but $text still contains the placeholders for the variables, like {{var myvar}} or {{store url=""}}. Is there a way to fill those placeholders when loading the template without sending the mail? I want to show the text to the user, but with filled placeholders.
Possible?
Thanks :)
Yes, it's possible.
The class Mage_Core_Model_Email_Template
has a method getProcessedTemplate()
. You only need to pass along the proper variables for your placeholders.
For example, if your template contains placeholders like this:
{{var firstname}} {{var lastname}}
you can use:
$sTemplate = Mage::getModel('core/email_template')
->load($templateId)
->getProcessedTemplate(array(
'firstname' => 'John',
'lastname' => 'Doe'
));
to get your placeholders resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With