{"id":56194,"date":"2016-07-29T16:02:41","date_gmt":"2016-07-29T16:02:41","guid":{"rendered":"http:\/\/webkul.com\/blog\/?p=56194"},"modified":"2024-02-22T09:18:40","modified_gmt":"2024-02-22T09:18:40","slug":"get-controller-url-email-template-magento2","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/","title":{"rendered":"Get Controller URL in Email Template file in Magento 2"},"content":{"rendered":"\n<p>Here, we are discussing how to get a controller URL in the mail template file according to the store.<\/p>\n\n\n\n<p>For example: If you want to add a link to the custom controller or store-wise login URL, then you can follow the given method.<\/p>\n\n\n\n<p>Here,\u00a0we write the code to send an email to a customer in which we add a customer login URL according to the store.<\/p>\n\n\n\n<p>first, create a method\u00a0that you\u00a0call the email\u00a0template file method to send mail :<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\n\t\n\tpublic function generateTemplate(){\n\t   $customerId = 4;\/\/any customer id\n\t   $customerModel = $this-&gt;_objectManager-&gt;get(\n             &#039;Magento\\Customer\\Model\\Customer&#039;\n           );\n        $customer = $customerModel-&gt;load($customerId);\n        $customerStoreId = $customer-&gt;getStoreId();\n        \/\/other variables which you want to pass in the template\n        $emailTempVariables&#091;&#039;store&#039;] = $this-&gt;_storeManager-&gt;getStore($customerStoreId);\n        $this-&gt;sendMail($emailTempVariables);\n\t}\n\tpublic function sendMail($variables){\n\t\t\/\/code to send mail\n\t}\n?&gt;<\/pre>\n\n\n\n<p><br>Here,<\/p>\n\n\n\n<p>$customerId is a customer ID.<\/p>\n\n\n\n<p>$customerModel is a customer model, that holds the data of the customer which has id $customerId.<\/p>\n\n\n\n<p>$customerStoreId is the store ID of a customer.<\/p>\n\n\n\n<p>$emailtempvariables is an array that holds the values that you want to pass in your email template file.<\/p>\n\n\n\n<p>sendmail is a function in which you write the code to send an email.<\/p>\n\n\n\n<p>You can check our blog &#8220;<a href=\"http:\/\/webkul.com\/blog\/magento2-create-use-custom-email-templates\/\" target=\"blank\" rel=\"noopener noreferrer\">create custom mail template in magento2<\/a>&#8220;<br>Now, create your template file with the code:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;!--@subject Customer Account Login url mail  @--&gt;\n\n\n{{template config_path=&quot;design\/email\/header_template&quot;}}\n\n&lt;table&gt;\n    &lt;tr class=&quot;email-intro&quot;&gt;\n        &lt;td&gt;\n            &lt;p class=&quot;greeting&quot;&gt;{{trans &quot;Customer&quot;}}&lt;\/p&gt;\n        &lt;\/td&gt;\n    &lt;\/tr&gt;\n    &lt;tr class=&quot;email-information&quot;&gt;\n        &lt;td&gt;\n            &lt;table class=&quot;query-details&quot;&gt;\n                &lt;tr&gt;\n                    &lt;td class=&quot;product-details&quot;&gt;\n                        &lt;p&gt;\n                            {{trans\n                                &#039;Please &lt;a href=&quot;%reset_url&quot;&gt;Click here&lt;\/a&gt; to login.&#039;\n\n                                reset_url=&quot;$this.getUrl($store,&#039;customer\/account\/login\/&#039;)&quot;\n                            |raw}}\n                        &lt;\/p&gt;\n                    &lt;\/td&gt;\n                &lt;\/tr&gt;\n            &lt;\/table&gt;\n        &lt;\/td&gt;\n    &lt;\/tr&gt;\n&lt;\/table&gt;\n\n{{template config_path=&quot;design\/email\/footer_template&quot;}}<\/pre>\n\n\n\n<p>Here,<\/p>\n\n\n\n<p>rest_url is a variable in which we get the URL according to the store,\u00a0and it returns the customer login URL according to the store.<\/p>\n\n\n\n<p>I hope this blog will help you with getting the Controller URL in the Email Template file in Magento 2. You may also check our wide range of best\u00a0<a href=\"https:\/\/store.webkul.com\/Magento-2.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 Extensions<\/a>.<\/p>\n\n\n\n<p>Please reach out to our team via a&nbsp;<a href=\"https:\/\/webkul.uvdesk.com\/en\/customer\/create-ticket\/\" target=\"_blank\" rel=\"noreferrer noopener\">support ticket<\/a>&nbsp;if you have any queries.<\/p>\n\n\n\n<p>Try this and if you have any queries then just comment below \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here, we are discussing how to get a controller URL in the mail template file according to the store. For example: If you want to add a link to the custom controller or store-wise login URL, then you can follow the given method. Here,\u00a0we write the code to send an email to a customer in <a href=\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":68,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[302],"tags":[2070],"class_list":["post-56194","post","type-post","status-publish","format-standard","hentry","category-magento2","tag-magento2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get Controller URL in Email Template file in Magento 2<\/title>\n<meta name=\"description\" content=\"In this blog we will discuss Get controller url in email template file Magento 2.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Controller URL in Email Template file in Magento 2\" \/>\n<meta property=\"og:description\" content=\"In this blog we will discuss Get controller url in email template file Magento 2.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-29T16:02:41+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-02-22T09:18:40+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bulbul\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bulbul\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\"},\"author\":{\"name\":\"Bulbul\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\"},\"headline\":\"Get Controller URL in Email Template file in Magento 2\",\"datePublished\":\"2016-07-29T16:02:41+00:00\",\"dateModified\":\"2024-02-22T09:18:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\"},\"wordCount\":258,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"Magento2\"],\"articleSection\":[\"Magento2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\",\"url\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\",\"name\":\"Get Controller URL in Email Template file in Magento 2\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2016-07-29T16:02:41+00:00\",\"dateModified\":\"2024-02-22T09:18:40+00:00\",\"description\":\"In this blog we will discuss Get controller url in email template file Magento 2.\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Controller URL in Email Template file in Magento 2\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e\",\"name\":\"Bulbul\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Bulbul\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/bulbul896\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Controller URL in Email Template file in Magento 2","description":"In this blog we will discuss Get controller url in email template file Magento 2.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/","og_locale":"en_US","og_type":"article","og_title":"Get Controller URL in Email Template file in Magento 2","og_description":"In this blog we will discuss Get controller url in email template file Magento 2.","og_url":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2016-07-29T16:02:41+00:00","article_modified_time":"2024-02-22T09:18:40+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Bulbul","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Bulbul","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/"},"author":{"name":"Bulbul","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e"},"headline":"Get Controller URL in Email Template file in Magento 2","datePublished":"2016-07-29T16:02:41+00:00","dateModified":"2024-02-22T09:18:40+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/"},"wordCount":258,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["Magento2"],"articleSection":["Magento2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/","url":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/","name":"Get Controller URL in Email Template file in Magento 2","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2016-07-29T16:02:41+00:00","dateModified":"2024-02-22T09:18:40+00:00","description":"In this blog we will discuss Get controller url in email template file Magento 2.","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/get-controller-url-email-template-magento2\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get Controller URL in Email Template file in Magento 2"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/c9c6288b3950490ffdb37cb2a526996e","name":"Bulbul","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/37ea7175f5ae6557d01bb38e147f6a02a540714ecdb71770d8ec554d4d34c23f?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Bulbul"},"url":"https:\/\/webkul.com\/blog\/author\/bulbul896\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/56194","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/68"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=56194"}],"version-history":[{"count":12,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/56194\/revisions"}],"predecessor-version":[{"id":423772,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/56194\/revisions\/423772"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=56194"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=56194"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=56194"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}