加载Magento邮件模板并通过代码填充其变量? [英] Loading a Magento mail template and fill its vars from code?
问题描述
我正在像这样加载我的邮件模板:
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');
这可行,但是 $ text 仍包含变量的占位符,例如{{var myvar}}或{{store url ="}}.在不发送邮件的情况下加载模板时,是否可以填充这些占位符?我想向用户显示文本,但使用占位符填充.
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.
可能吗?
谢谢:)
推荐答案
是的,有可能.
类Mage_Core_Model_Email_Template
具有方法getProcessedTemplate()
.您只需要为占位符传递适当的变量即可.
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}}
您可以使用:
$sTemplate = Mage::getModel('core/email_template')
->load($templateId)
->getProcessedTemplate(array(
'firstname' => 'John',
'lastname' => 'Doe'
));
让您的占位符得到解决.
to get your placeholders resolved.
这篇关于加载Magento邮件模板并通过代码填充其变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!