How To

Magento 2: How to Get System Configurations Value in Email Templates

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 😊

Click to rate this post!
[Total: 7 Average: 4.4]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

View Comments

Recent Posts

Magento 2: Add Quantity Increment and Decrement on Category Page

Hello Magento Friends, In this blog, we will discuss about adding quantity increment and decrement…

4 hours ago

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

3 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

5 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

5 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

6 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

1 week ago