【问题标题】:How does the email template vars works within Magento?电子邮件模板变量如何在 Magento 中工作?
【发布时间】:2011-04-04 08:53:08
【问题描述】:

我需要创建一个使用从 cron 运行的观察者发送的特定电子邮件模板。
当我收到电子邮件时,我没有提供的变量的值。

$vars = array(
    'product'  => $product,
    'customer' => $customer
);

$mailTemplate->sendTransactional(
    $mailId,
    'general',
    $customer->getData('email'),
    $customer->getData('firstname') . ' ' . $customer->getData('lastname'),
    $vars
);

$product$customer 都是模型集合(Product_Collection 和 Customer_Collection)中的对象。

在我的模板中,我尝试像这样访问它们:

Dear {{htmlescape var=$customer.name}},
<p>Check {{htmlescape var=$product.name}}</p>

有什么想法吗?

顺便问一下,我怎样才能为我的产品构建 url? (让客户点击链接查看产品)

【问题讨论】:

  • 在应用实际过滤器时,如果您的变量已经到位,请拍手开始调试。最好使用 xdebug.org 并与您的 php ide 一起使用,您可以启动调试会话

标签: php email templates magento


【解决方案1】:

尝试在变量上不使用美元符号。查看默认的电子邮件模板,它们似乎不包含那些美元符号。

希望有帮助!

谢谢, 乔

【讨论】:

    【解决方案2】:

    这些参数被标记化,而. 之前的部分被认为是对象,之后的字符串是要在该对象上调用的method

    所以$customer.name 在模板处理期间被评估为$customer-&gt;name()。要检索客户的姓名,您可以在 PHP 中调用 $customer-&gt;getName(),因此在模板中使用 $customer.getName()

    但是对于不同的模板方法应该如何传递参数有一个重要的区别。我可以从源代码中收集到,所有将参数作为单个参数而没有属性分配的模板方法都应该在没有前导 $ 的情况下调用,而所有使用属性的方法都需要 $ 作为前缀。

    属性赋值

    {{htmlescape var=$customer.getName()}}
    

    但作为单个参数

    {{var customer.getName()}}
    

    通过查看*Directive() 函数,查找Mage_Core_Model_Email_Template_Filter 类中的所有可用方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-10
      相关资源
      最近更新 更多