Hello Magento Friends ?,
Hope you are all well and good. Today’s technical solution is Magento 2: How to Get System Configurations Value in Email Templates. If by any chance you skipped our last blog, How to Restrict Customer to Access CMS Page and Redirect to Login Page in Magento 2.
Email templates may be a header, footer, or any other custom email template. By default, Magento 2 provides some default functionalities to add some fixed text as well as variables to display dynamic data in Magento 2 email templates.
But what if you want to use system configurations value in your email templates?
One way to use system configuration value in the template is to get that value before sending the email and that value will be passed as a variable. But Magento 2 also provides a direct way to use system configuration value in templates.
So, let us do ?
Magento 2: How to Get System Configurations Value in Email Templates
Note: Here we have used the contact email template and demonstrated how we can get system configuration value on that template.
Step 1: Update your submitted_form.html file inside vendor/magento/module-contact/view/frontend/email folder and update your code by below code reference (you can use file path as per your need)
<!-- /** * 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"}}
Step 2: Finally run the below command
php bin/magento cache:flush
That’s it.
Conclusion:
In this manner, you can get system configurations value in email templates. You may also like to know How to Customize Email Templates in Magento 2. In case of any mishap while implementing the above steps, mention in the comment. Share the article with your fellow Magento friends. Stay tuned for more such solutions.
Happy Coding ?
It is not working for custom config value in custom email tesmplates