我可以在 prestashop 电子邮件模板中使用条件

I can use conditional in prestashop email templates

我对 prestashop 1.7.2 中的模板有疑问。在 International/Translation 电子邮件正文中,我可以使用 {if payment="bankwire"}Any to say{/if} 或者我不能在模板电子邮件中使用条件句?

不,您不能在邮件模板中使用条件。您应该复制模板并编辑 PHP 代码以使用一个或另一个。

您可以直接修改 PS 1.7 中触发电子邮件发送的 PHP 部分,并在实际调用发送之前在字符串中添加您自己解析的 HTML ,在Email:Send() 使用的 $data 部分。

通过我对订单确认电子邮件通知代码的检查,我发现每次向 HTML 电子邮件模板发送一个 $data 数组。您可能知道,电子邮件模板中 {value} 中的那些值是实际变量内容,来自 PHP 控制器或 class 端。

所以,基本上,您可以在 PHP class/controller 中执行类似的操作,并将新值添加到 $data 数组(我建议创建覆盖或挂钩):

//Just as an example with a ternary.
//Note how I use a {} wrapping the string content. It seems to be a convention or something for PS HTML templates, to escape properly variables from normal text.

$data['{your_conditional_html}'] = $some_value ? "<div>This is great!</div>" : "<div>No, this is not great...</div>";

然后在您的电子邮件模板中:

{your_conditional_html}

就是这样。完毕。您现在应该在 HTML 模板中拥有动态和验证的内容。在 PHP 部分执行您喜欢的任何条件逻辑,以创建发送到电子邮件模板的 HTML 或文本内容。

此致。