当前位置: 技术文章>> Magento 2:如何在电子邮件模板中获取系统配置值

文章标题:Magento 2:如何在电子邮件模板中获取系统配置值
  • 文章分类: Magento
  • 25520 阅读
系统学习magento二次开发,推荐小册:《Magento中文全栈二次开发 》

本小册面向Magento2以上版本,书代码及示例兼容magento2.0-2.4版本。涵盖了magento前端开发,后端开发,magento2主题,magento2重写,magento2 layout,magento2控制器,magento2 block等相关内容,带领您成为magento开发技术专家。


Magento 2:如何在电子邮件模板中获取系统配置值

注意:在这里,我们使用了联系人电子邮件模板,并演示了如何在该模板上获取系统配置值。

步骤1:更新vendor/magento/module-contact/view/frontend/email 文件夹中的submitted_form.html文件,并通过以下代码参考更新代码(您可以根据需要使用文件路径)

<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<!--@subject {{trans "Contact Form"}} @-->
<!--@vars {
"var data.comment":"Comment",
"var data.email":"Sender Email",
"var data.name":"Sender Name",
"var data.telephone":"Sender Telephone"
} @-->
{{template config_path="design/email/header_template"}}
<table class="message-details">
    <tr>
        <td><strong>{{trans "Name"}}</strong></td>
        <td>{{var data.name}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Email"}}</strong></td>
        <td>{{var data.email}}</td>
    </tr>
    <tr>
        <td><strong>{{trans "Phone"}}</strong></td>
        <td>{{var data.telephone}}</td>
    </tr>
</table>
<p><strong>{{trans "Message"}}</strong></p>
<p>{{var data.comment}}</p>
 
<!-- Code For Getting System Configuration Value Start-→
 
<p><strong>{{trans "Store Contact Number"}}</strong></p>
<p>{{config path="general/store_information/phone"}}</p>
 
<!-- Code For Getting System Configuration Value End-→
 
{{template config_path="design/email/footer_template"}}

步骤2:最后运行以下命令

php bin/magento cache:flush

结论:

通过这种方式,您可以在电子邮件模板中获取系统配置值。


推荐文章