1

I want to add my custom link in contact email link. For that, I have created a new email template for the contact email but this is in plain text. enter image description here

So how can I add a link to contact email template OR how can I overwrite the contact email template in my custom module/theme?


As per @VivekKumar answer, please check the below image.

enter image description here


As per @Akhilesh answer, I have overwrite the email_template.xml file in my theme as below. Clear the cache - run content deploy but it loads the template in the plain text.

enter image description here

3
  • I have used the same code and it works fine for me, try flushing browser and magento cache to see if it fixes the problem Commented May 4, 2018 at 10:43
  • I have done but it still displays as plain text. Commented May 4, 2018 at 10:50
  • Is there anyone who knows the solution? Commented May 9, 2018 at 7:29

2 Answers 2

3

Place your link's html inside {{trans '<your html>' |raw}} enclosure to ask it to be rendered as html and not as text. So, it should look as follows :

{{trans '<a href="www.example.com">example</a>'|raw}}
1
  • I tried, please check the updated answer. Commented May 4, 2018 at 10:36
2

You will need to change the template type to html from text in file

vendor/magento/module-contact/etc/email_templates.xml

Take this file in your theme folder and change from text to html

<template id="contact_email_email_template" label="Contact Form" file="submitted_form.html" type="html" module="Magento_Contact" area="frontend"/>
6
  • Seems to be the correct answer. Commented May 4, 2018 at 11:16
  • Tried but it still loads the template in plain text. Commented May 4, 2018 at 11:45
  • Changing type of entire email templates to html just to make a link work doesnt seem fine to me. Commented May 4, 2018 at 12:29
  • @VivekKumar vendor/magento/framework/Mail/Template/TransportBuilder.php check prepareMessage function. It is checking that template file is plain text or html. getTemplate() function will set the all template variables which we declare in email_templates.xml file. Commented May 4, 2018 at 12:41
  • @JigarDhaduk Hopefully you deploy and clear cache after making this changes. Commented May 4, 2018 at 12:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.